Information Flow Of Creating A New Object With CoreDataTableViewController L5.4.3

We start with an IBAction listening for a button presses to kick off creating a new Notebook object. Core Data will do most of the heavy lifting here.

    @IBAction func addNewNotebook(_ sender: AnyObject) {
        // Create a new notebook... and Core Data takes care of the rest
        let nb = Notebook(name: "New Notebook", context: fetchedResultsController!.managedObjectContext)
        print("Just created a notebook: \(nb)")
    }

How The Information Flows

information flow

The first thing that happens is the Context realizes that something has changed in the objects within it (a new Notebook has been created) when we click the addNewNotebook button and execute the code inside the IBAction above.

Therefore it sends the NSManagedObjectContextObjectsDidChangeNotification a notification with the new object as a payload.

NSFetchResultsController receives the notification and sends a delegate message to CoreDataTableViewController which in turn tells the TableView to update.