Lately I’ve spent some time wrtiting an app for myself. It is supposed to let you create tasks, mark them as done/undone and then track your progress. I’ve called it “Habit Tracker” and it is available here. While writing this utility I came across a few interesting issues and this blogpost will cover one of them.
The feature that “Habit tracker” surely needed was ability to store and load users tasks. Core data seemed a bit overkill for me, so I decided to use NSKeyedArchiver/Unarchiver.
First of all lets create a class which we want to archive. It will be called Task. In order to save and load it with use of NSKeyedArchiver/Unarchiver we have to make our class implements two methods provided by protocol <NSCoding>.
Now lets create our example Task class.
Now we are able to properly store our tasks in files.
If we use iOS Simulator, all files that are saved by us are stored in our app’s folder. Using my saving code you will find file named “FILE_NAME” under:
By using this command you can get your currently running iOS Simulator ID: