Aleksandar • Vacić

iOS bits and pieces

State restoration for modal view controllers

In my first post about state restoration on iOS 6 (or newer), I explained how you should use restorationIdentifier for the view controllers that are part of the on-load UI (and thus created in AppDelegate) and restorationClass to create and return controllers which are deeper in navigation stack.

If you do that, UIKit will take care of restoring the UITabBarController and UINavigationController and you just deal with view controllers beyond the topViewController inside the navigation controller hierarchy.

That’s still a good general guideline. However, as is usually the case, there are exceptions.

Apps have infinite worth

Florian Kugler wrote a post yesterday arguing that for most people the apps we write are worth next to nothing. That their value is determined by how much are people paying for that. Increasingly, that’s a dolar or nothing. Hence, we - app developers - create products of little value.

Here’s a direct quote:

Another approach – and I would argue a more insightful one – is to learn about the nature of the market we’re working in. And not only about the market as an abstract whole, but about the value of our products specifically. The economic reality is that most apps offer next to no value to people. They might say otherwise when asked about, but their actions speak pretty clearly: A cup of coffee is worth more than almost every app on the store.

This is so not true.

Fix corrupted SQLite3 database

I tackled a very strange support request last few days, which escalated to the point that customer extracted the .sqlite database from the iPhone and sent it to me. I’m a SQLite3 rookie, but this worked for this particular case and I need to write for future reference. :)

When trying to open the file, Base would complain that file is either encrypted or damaged. When I placed it on my test device and started the app, it would immediatelly crash with this message in the console:

disk image is malformed

This usually happen if database file is accessed while still in use, but it can also happen if app is terminated during the save. In any case, I now needed to fix the database file and here’s how to do that.

Using State Preservation with Core Data

In previous post on state preservation and restoration, I presented the basics. This post deals with something that’s fairly common in data-driven apps.

Core Data is one of my favourite iOS frameworks; I use it in almost all of my apps, anything that requires even a minor object graph. So, let’s see how to save/restore state of table views (it’s the same for collection views) fueled by NSFetchedResultsController.