This post is the first of a ten-part series called Exploring Codable and Core Data in Swift 4.
What is Codable?
Apple's Foundation framework provides two protocols for encoding and decoding objects in Objective-C:
NSSecureCoding. The introduction of Swift 4 has brought us two new protocols to handle data encoding and decoding:
Decodable. Collectively, these protocols are known as
Codable is a type alias for the
/// A type that can convert itself into and out of an external representation. typealias Codable = Decodable & Encodable
Now, what exactly is an external representation anyway? These representations can consist of property lists, JSON, XML, protobuf, and other flat binary representations. For this series, we'll be using JSON because it's a common way of sending or receiving data over a network connections.
In our next post, titled Decoding Custom Types with Decodable (coming soon), we'll discover how to turn JSON objects into
Decodable data models automatically and manually in Swift.