Going Offline Errata

In Chapter 17: Going Offline, page 324 The code the clears the cached data files has a minor issue. The code in the book is for(NSString *path in cachedItems) { [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; } The path variable in this code is just the file name and not the full path and as such, doesn’t delete the cached data file. Thanks to Brian for pointing this...

Read More

KVO Tradeoffs Errata

In Chapter 15, I say: The first call to removeObsever:forKeyPath: removes both previous observers. The second call will crash. This may sound contrived, but consider the case where both you and your superclass are observing the same object’s property. There is no easy way to implement that without special knowledge about your superclass’s implementation. If your superclass is a UIKit class,...

Read More

The Singleton pattern

In chapter 4, we recommend using +initialize to create singletons. This used to be a good pattern, but it’s become dated since the addition of Grand Central Dispatch. It’s time to update our pattern to modern tools. Our new recommendation is the GCD way (replace id with your classname): + (id)sharedManager { static id sharedManager; static dispatch_once_t once; ...

Read More

Leading Underscores

Have written something that you’d swear you’d never have written because it’s wrong and you know it’s wrong? But you did anyway? In Chapter 3, I said that Apple reserves leading underscores in ivar names. This isn’t true. Apple reserves leading underscores in method names, but not ivar names. While I believe avoiding a leading underscore was valuable in the past for...

Read More