I am using NSCoding to save and restore my view controllers. However I'm saving to disk the navigation stack + view controllers every time a view controller is pushed or popped.
This is not energy efficient, and there's a better way.
Think of NSUserDefaults
. It saves the changes somewhere in memory (and if called repeatedly as it is, just overwrite) and when the synchronize
method is called it writes them to disk. This is genuinely done, and is super energy efficient.
So can I implement something like this? On every call to save changes somewhere in memory and when a synchronize/writeToDisk
method is called to purge the memory cache and write them to disk.
Any ideas will be greatly appreciated!
My idea is to use NSCache
, and in application:willResignActive
or application:willTerminate
to get the object in the cache and write it do disk.
Thanks so much!