Chapter 24. Saving LioNs
This chapter covers
- Sandboxes
- Saving LioN objects to a file
- Loading LioN objects from a file
- The NSCoding protocol
Now you have the ability to create new LioNs and edit them, but when you close the app and open it again, all of your data is gone. You can fix that, though, so let’s get to it. The purpose of this chapter is to save the lionData array to the iPhone so the data loads every time you load the app, and the data saves to the phone every time you close the app.
Saving data to your iOS device isn’t that different from saving a file to your computer. When you’re on the computer, you pick any location that you have access to and click Save. When you’re on an iPhone or iPad, though, the programmer (you) picks the location to save the file, and it’s saved automatically so the user doesn’t have to. Apple put some security measures in place for the iPad and iPhone so you can only save the app file to specific locations—called sandboxes.