Chapter 11. Local data persistence
This chapter covers
- Storing app state on the device
- Storing user preferences on the device
- Using different techniques for storing data on the device
In this chapter, we’ll take a lightning tour of several options for persisting data locally on the device. We can’t comprehensively cover all features of all alternatives in one chapter, but we’ll explore the basics of the different options and the differences in approaches, so you can choose for yourself which option you prefer or which is more appropriate for a project.
Specifically, we’ll explore storing data using
- State preservation and restoration— Your app remembers where you left it.
- User defaults— Your app remembers your preferences.
- Property lists— Serialize your model objects into a type of structured data often used by Apple.
- XML— Serialize your model objects into an XML format.
- JSON— Encode your model objects into the JSON format.
- Archiving objects— Store model objects directly to the device by making them encodable.
- SQLite— Use SQLite operations to store data in a local database.
- Core data— Store data using object-oriented code built over a relational database.
Along the way, we’ll also explore
- App delegate— Responding to app-level events in your app’s delegate.
- Error handling— Dealing with errors that may occur during your app’s execution.
- Using Objective-C in a Swift project— Creating a bridging header to import Objective-C classes in your Swift project.