Application requirements evolve, which require us to refactor existing features. For the most part, Xcode's built-in refactoring tools work well; however, an area where the refactoring tools can't help is with stringy APIs. Core Data seems to be full of stringy method parameters - in this ar…
A common mistake I see over and over again in code is the accidental double retain. This happens when an object is set to a property that has the attribute retain which results in a memory leak. Let's look at an example of this happening: @property (retain) UIView *doubleRetainedView; @pro…
The only time you should call [self release] is if during the initialization of your object an error occurs that causes you to return nil. - (id) initWithData:(NSData *)userData error:(NSError **)error { if(!userData){ if(error){ *error = //set up err…
In Objective-C you pass by reference by placing the "&" symbol (minus the quote marks) in-front of the variable name i.e. &var instead of just var . This informs the compiler to pass the memory address of the variable rather than its value. This is useful when you want to update th…
I found it surprisingly tricky to track down how to hide the tabbar on certain view controllers without ending up with a white area where the tabbar would have been. What you need to do is set the tabbar hidden property on the UIViewController you are about to push rather than on the UITabbarControl…
I was looking through the Apple documentation and discovered their take on a singleton class that I thought I should share here: static MyGizmoClass *sharedGizmoManager = nil; + (MyGizmoClass*)sharedManager { if (sharedGizmoManager == nil) { sharedGizmoManager = [[super allocWithZone:…
NSUserDefaults is a great way to save small amounts of data that you want to persistent across application "sessions" (especially where a database would be overkill). Saving data: [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KEY_TO_IDENTIFY_INFORMATION]; In the above, we s…
Often when creating a delegate relationship between two objects: A (delegate) and B (delegating object), you can sometimes run into the scenario where the delegating object outlives the delegate. Meaning that if we don't inform B that A is dealloc'ed we could end up with a fatal app crash. T…
Sorting an array of NSNumber elements in Objective-C is fairly straight forward: NSArray *unsortedArray = @[@(9), @(5), @(1), @(2), @(4)]; NSArray *sortedArray = [unsortedArray sortedArrayUsingSelector:@selector(compare:)]; NSLog(@"sortedArray: %@", sortedArray); But what happens if we…