Persistence Concepts Flashcards
iOS Persistence:
What options to persist data are available on iOS?
Depending on the case and the amount of data, there are different ways to store data. Examples are User Defaults, saving Files, Keychain, Core Data. There are also third party libraries like Realm.
iOS Persistence:
In what cases would you use UserDefaults?
UserDefaults is a great way to save a small amount of data. You can store basic types such as Bool, Int, String etc., and also more complex types like arrays and dictionaries.
iOS Persistence:
When would you use the Keychain to store data?
Keychain is a good choice, if you want to save highly sensitive and secure data like passwords, keys etc. When using Keychain, it automatically takes care of data encryption before it is stored in the file system.
iOS Persistence:
How would you persist large amounts of data objects with relationships in iOS?
Core Data or Realm Database are often used on iOS to deal with a large amount of data.
Core Data is Apple’s native solution for persistence. Through Core Data’s model editor, you define your data’s types and relationships, and generate corresponding class definitions.
Realm Database is a highly supported open source library that is also available for Android. It is popular because it is easy to use and really fast.
These are not the only options of course. For example, you could also use a SQL database, there are some SQL libraries around, like SQLite.swift.
iOS Persistence:
Explain what data migration means and when it needs to be done?
Data migration is often necessary when you need to make changes to the data model. So every time when the data model needs a change, e.g. for a new feature request, you’ll need to create a new version of the data model and provide a migration path.
An alternative to migration is simply deleting and rebuilding the data store. But this is only an option, if the stored user data can fully be restored, e.g. from a backend api.