Blog

Exploring Codable and Core Data in Swift 4

Recently, I had asked the iOS community on LinkedIn and Twitter if creating a framework which allowed Core Data to support Codable in Swift and Objective-C would be valuable:

Ever since Codable was introduced in Swift 4 / Xcode 9.0, I’ve been researching ways to combine the two services to provide an iOS framework to reduce their complexities, while improving maintenance and scalability. Most iOS applications these days are data-driven and receive their data from server-side API calls, process the response into their own data structures, and display that data to the User Interface.

Diagram displaying a common iOS application architecture when sending/receiving from a web server | © 2018 by PXPGraphics, Inc. All rights reserved.

To simplify this data flow, the data, caching, and persistence logic should be abstracted into their own layers within the application architecture — this is the purpose for the proposed framework, called Badger(?), which I hope to release in 2019. For example, some of the goals of the proposed framework include:

  • JSON serialization

  • Model validation

  • Object graph management

  • In-memory caching

  • On-disk persistence

  • Logging and error handling

Diagram displaying similarities and differences in responsibilities between Codable and Core Data | © 2018 by PXPGraphics, Inc. All rights reserved.

  

Due to the many responsibilities of this framework, I’ve decided to break down the components into this blog series, titled Exploring Codable and Core Data. To help lower the barrier of entry for readers, I’ve decided to focus on a few essential topics per post. The series will consist of the following topics:

  1. Getting Started with Codable

  2. Decoding Custom Types with Decodable (coming soon)

  3. Encoding Custom Types with Encodable (coming soon)

  4. Getting Started with Core Data (coming soon)

  5. Making Core Data Your Model Layer (coming soon)

  6. Creating Your Core Data Stack (coming soon)

  7. Saving Codable Models to Core Data (coming soon)

  8. Fetching Codable Models from Core Data (coming soon)

  9. Testing Codable Models (coming soon)

  10. Testing Core Data Models (coming soon)

Note: I strongly believe sharing knowledge this way helps readers from all levels of experience and backgrounds to learn and improve their skills, and help the community grow and build together. So any feedback, questions, or comments from you would be greatly appreciated. Thanks in advance, and stay tuned for updates!