I was lucky enough to get an invite to the Apple 4k Tech Talk in London a couple of weeks ago. It was a worth while trip to the big smoke just for some of the snippets of information your get from some of the talks. Sometimes it doesn’t matter how many forums or blogs you read, how many articles or books you scour through, it takes someone talking to make something make sense.
I didn’t take copious notes like many other people did; there were a large number of people sat there typing in to their Mac Books, almost verbatim anything said!
Anyway, here are a few items I scribbled down that may be of interest.
The first two sessions I took were “Effective iPhone App Development” by Lawrence Coopet.
1. When storing config/session states, be careful about writing lots of objects into a dictionary as individual items. Create a session object and write that instead and don’t just write everything to NSUserDefaults.
2. Think about where you store this data… Archive and implement NSCoding and Data Recovery.
3. Use SQLite
4. Use CoreData
5. Store sensitive data in the KeyChain. This has the benefit of being able to share between projects – company data – application data.
When Caching data, make sure you place it in the correct place and never hard code your paths to this data.
All the paths are stored in NSPathUtilities.
NSTemporaryDirectory – this will always be cleared and will never be backed up.
NSCacheDirectory – this is saved, can be cleared, but will never be backed up.
NSDocumentsDirectory – never cleared, always backed up.
Choosing the right place for your data will determine how much iTunes has to backup when syncing your device.
Targetting iPhone OS
1. You should ALWAYS set your Base SDK to the most current OS version – ie. currently 3.1.2 – regardless of which OS you are considering deploying to.
2. Set you Deployment Target to the minimum OS you want your app to run on.
3. You should check for presence of OS features in your code. eg use NSClassFromString and respondsToSelector. However do this at the start of your app and set flags accordingly so that you are not taking speed hits during normal app operation. checking straight global C functions is very quick.
eg if ( UISaveVideoAtPathToSavedPhotoAlbum )
1. Stay focused!
2. The best system is generally – List View – Info View – Detail View. Allow the user to choose to drill down on data rather than forcing too much information on them in one go.
3. Always use the 1 screen 1 controller model.
4. Make sure you are not hardcoding references back to other objects in your application. Using the Model Controller View model your controller talks back to your model but your model should never talk directly to your controller. Your controller talks to you view but your view should never talk back to your controller. And you should never every have your view talk directly to your model. If parent communication needs to take place, then implement delegates. This way you can avoid App specific communication paths.
5. Use Delegates
6. Use Notifications through NSNotificationCentre
1. Make use of the measurement tools regularly – checking for leaks and generally memory usage.
2. Under Snow Leopard make use of XCode Static Analysis – it’s a fantastic tool. (BTW: It really is!)
3. Use the 1 controller 1 nib model.
Application Life Cycle
1. Prefix your classnames with your own token to avoid namespace collisions. eg UI, NS etc…
2. Avoid underscores at the start of method names – these are reserved to Apple.
Proper Code Paths
1. Follow correct code paths. eg. You implement drawRect and call setNeedsDisplay. NEVER call drawRect.
Make sure you handle applicationWillResignActive, applicationDidResumeActive, and applicationWillTerminate.
1. Make sure you use the Async API for Networking and Reachability.
2. Use NSTimer – don’t sit around in threads counting down!
3. Use NSOperation and NSOperationQue. Subclass NSOperation and override main.
4. Keep object access confined to one thread.
5. Design out the need to use locking/signalling/syncing
6. Avoid performSelectorInBackground and detachNewThreadSelector – if you are using these then you are doing it wrong. Use NSOperation.