An overview of iOS persistence

There are two types of data persistence: file and DB, and the third type of keychain estimates provided by the system.

The breakdown is as follows:

  • File class
    • plist
      • Direct serialization of collection classes (writeToFile)
        • The explicit declarationatomically:YESIs thread-safe
      • NSUserDefaults
        • It is used to store key and value pairs, which is thread safe
    • NSKeyedArchiver
      • Model implements NSCoding protocol, which is not thread safe
  • The DB class
    • SQLite3
      • Use a very wide range of cross-platform, lightweight, relational DB
      • Non-thread-safe
    • CoreData
      • Official SQLite-based ORM framework
    • The third party
      • FMDB
        • Object-oriented encapsulation of SQLite, thread-safe
      • Realm
        • Own a set of engines, excellent object-oriented interface
  • keychain
    • A keychain is a mechanism provided by the system to store user names, passwords, and other credentials.
    • The feature is that APP deletion will not be lost, so it is often used to save the unique identity of the user (another method available is IDFA, which can be disabled by the user).

Reference:

Summary of iOS data local persistence methods

IOS Interview – Database Comparison: SQLite vs. Core Data vs. Realm