It’s common for iOS applications to preserve their state when quitting, so that the next time the user launches the app, their previous session is restored. Apple reduced the development burden for this state restoration in iOS 6 with their State Preservation and Restoration APIs. Even with the APIs, though, each view controller is responsible for preserving its own state, and that includes any references to core data objects that are being displayed in a table or detail view.
Of course, the persistence of
NSManagedObjects is handled by the core data stack, so the view controllers just need to store references that will allow them to refetch the objects during restoration. What’s a straight-forward way to implement encoding those references?
I saw Square’s PonyDebugger project on GitHub a while back, starred it, and made a mental note to try it out in my next iOS project. It’s simply fantastic — easy to setup and incredible to use. If you’re an iOS developer be sure to add this one to your debugging toolkit.
PonyDebugger is remote debugging toolset that uses a gateway server and the Chrome Developer Tools to allow you to inspect NSURLConnection based network activity, Core Data managed object contexts, and your view hierarchy remotely while your application is running.
Core Data provides a capable framework for connecting data to an iOS user interface. The framework doesn’t so much reduce code as it does abstract the SQLite interface in order to support advanced features. However, in doing so it masks certain implementation decisions that can result in inefficient, less-than-instant queries when a table reaches 5-10k records. Since these queries are often run on the main thread for easy integration with the UI, they lead to unresponsive apps.
Solving these slowdowns requires understanding more about SQLite and Core Data’s connection to it. For both technologies, there are simple analytical tools and standard solutions for common optimization problems. (more…)
In order to store private data in an iOS Core Data database, there are several methods available for encryption, including: