Persisting View Controllers With Core Data Objects

Photo by Benh LIEU SONG, http://www.flickr.com/photos/blieusong/7234335792

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?

(more…)

Inspecting iOS Apps with PonyDebugger

Image of code by florian-olivo

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.

Unicorn LogoPonyDebugger 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.

(more…)

Optimizing Core Data searches and sorts

Photo of 5 story library inside looking down by Tobias Fischer on Unsplash

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…)