Codable
is an undisputed winner when it comes to serializing data coming from network requests in JSON form.
But when you’re considering solutions for persisting data to disk, such as UserDefaults
, FileManager
, or Keychain
you have another option - NSCoding
protocol.
NSCoding
used to be the preferred way to serialize data for storage on iOS before Codable
was released. Nowadays Codable
’s very convenient but comes with limitations - for example, it is not as straightforward to serialize custom data structure that has inheritance in it. With NSCoding
, there is no such limitation.
At the same time, using NSCoding
you’d likely need to write extra boilerplate code to map data with NSKeyedArchiver
/NSKeyedUnarchiver
…
What do you, dear reader, use these days for data serialization for persistence?