Chapter 11: Handling Core Data in SwiftUI

Core Data is definitely one of the most essential Apple frameworks in the iOS and macOS ecosystem. Core Data provides persistence, meaning it can save data outside the app's memory, and the data you saved can be retrieved after you restart your app.

Given its importance, it's not a surprise that Apple has implemented some extensions for Core Data to make it work nicely with SwiftUI.

In Core Data language, a stored object is an instance of NSManagedObject, and from iOS 13, NSManagedObject conforms to the ObservableObject protocol so that it can be observed directly by a SwiftUI's view.

Also, NSManagedObjectContext is injected into the environment of the View's hierarchy so that the SwiftUI's View can ...

Get SwiftUI Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.