We explored the basics of Core Data in previous articles like this one, where the data was managed directly on the View. This is fine for managing simple data sets, but when it starts to get complicated it's recommended to manage that data from a ViewModel.
Data Model file and entity Person
will be created in the same way as in the previous Core Data articles. Then we can create a Core Data manager called CoreData
.
import CoreData
class CoreData {
let container = NSPersistentContainer(name: "Model")
static let shared = CoreData()
private init() {
container.loadPersistentStores { description, error in
if let error = error {
print("Core Data failed to load: \(error.localizedDescription)")
}
}
}
}
Continue reading
Access to all the content with our plans.
- Junior level content
- Senior level content
- Expert level content
- Extra content
- Question submissions
Monthly
Yearly
Be the first to comment