So, now that we have seen our Core Data model persisting data, and our Cocoa Bindings loading and updating the data for us, it's time to go into a little more depth and discover the rich framework of functionality that we have signed up for, by choosing to implement our data model and persistence using Core Data.
We mentioned previously that most of the AppDelegate
class's boilerplate code was going to be dispensed with, and we'll do this now.
At the moment, we are looking at a lot of code involved in creating the Core Data stack. Your AppDelegate.swift
file will look very much like this one at the moment:
We won't need all of that. At least, we won't need all that code; the complete Core Data stack can now be created within an NSPersistenceContainer
, through which we can access as much of the stack as we require.
To do this, we make three changes to the AppDelegate
class:
- We initialize (lazily) an instance of
NSPersistentContainer
using our app...