Skip to content

DA7. Data Persistence in iOS

Using core data, you can store data in the local device storage. It has the benefit that you can access that data offline without the internet, but at the same time will take up much space of the device on which the app is installed. Alternatively, you can store data in cloud storage which will let your app take less device storage. Compare and contrast both the data persistence alternatives.

Choosing between storing data on a remote server or locally on the client’s device is a decision that depends on the type of data that is being stored and the use case of the application; but in general, data should always end up in the cloud on a remote server so that it is retrievable by the user from any device but all should be according to the privacy regulations and the user’s consent, but it can also be stored locally on the client’s device at the risk of losing it if the device is lost or damaged or app is uninstalled.

A more recent approach is to store data locally on the client’s device and then synchronize it to the cloud when the device is connected to the internet. This approach is more efficient as it reduces latency and bandwidth usage, makes applications more responsive, and allows the user to access the data offline. However, when the synchronization should happen depends on the use case of the application.

For realtime applications, the synchronization must happen as soon as the data is created or updated on the client’s device. For example, chat applications. For less time-sensitive applications, the synchronization can happen when the user opens the application or when the device is connected to the internet, or even periodically, e.g. every hour.

If either solution is chosen, the application need to store data locally using some Database solution, and synchronize to the remote server over the network, or use a solution that does both, e.g. Firebase.

Configurations Stores, that are used to store data locally on the client’s device, useful for storing small amounts of data, includes (Muramshetty, 2019):

  • NSUserDefaults: Not secure, Native, easy to use. save data as key-value pairs (text).
  • Plist (Property List): save data as XML or binary.
  • NsCoder: A protocol that enables an object to be encoded and decoded for archiving and distribution.

Databases, that are used to store data locally on the client’s device, useful for storing large amounts of data, includes (Muramshetty, 2019):

  • SQLite: lightweight file, does not load data to memory, does not require a separate server process.
  • Core Data: Native to IOS, default support for migrations and filters/search. nice interface. can be graph based or multithreaded. It is not compatible with Android stores and consumes memory.

Fully managed solutions, that are used to store data locally and synchronize it to the cloud, includes (Muramshetty, 2019):

  • Firebase: NoSQL. Realtime database with automatic syncing. Data stored as JSON. Compatible with all ios/android/web. All clients are notified when data changes.
  • Realm: Document based, can be shared between platforms.

References