Tag Archives: State Restoration

iOS State Restoration vs NSCoding

My goal was to create a mechanism to store user interface state in my app. So I decided to study Apple’s State Preservation and Restoration, that was first introduced in iOS 6. As far, as I could understand on my own experience use:
1. iOS State Preservation and Restoration, if you want to store navigation state in an app, that doesn’t change root controller of a window at some moment. It is convenient in this case.
2. NSCoding Protocol for simpler tasks, when you don’t want to navigate, but want to save interface states for only several forms, because it is much more flexible – you completely control the process.

I have tried to implement State Preservation and Restoration that was introduced in iOS 6 in my app but unfortunately I failed. The problem was that it’s mechanism is not flexible enough. It can restore state of View Controllers in a linear tree. But if your app as mine changes a Root Controller of your Window at some moment after user logins, for instance, this mechanism will not work. However, in other apps with simpler architecture it can be successfully used. It helps to bring a user right to the place where he stopped using your app last time even if app is removed from the background.

There is a good presentation on this topic on SlideShare.

I used this tutorial also. There is a code on GitHub, that works.

However, there is a good flexible alternative: saving objects to text files using NSCoding protocol: