From 67e6709f4ab4c8173de903fd269de3c2bdce2214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 3 Oct 2015 07:11:15 +0200 Subject: [PATCH] README.md --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a529a66b1..25e173480 100644 --- a/README.md +++ b/README.md @@ -1077,8 +1077,10 @@ Users of Core Data have recognized the roots of NSFetchedResultsControllerDelega Still, let's write an object that notifies, on the main thread, of modified database tables. Your view controllers can listen to those notifications and update their views accordingly. ```swift -class TableChangeObserver : TransactionObserverType { - var changedTableNames: Set = [] +let DatabaseTablesDidChangeNotification = "DatabaseTablesDidChangeNotification" +let ChangedTableNamesKey = "ChangedTableNames" +class TableChangeObserver : NSObject, TransactionObserverType { + private var changedTableNames: Set = [] func databaseDidChangeWithEvent(event: DatabaseEvent) { // Remember the name of the changed table: @@ -1086,23 +1088,23 @@ class TableChangeObserver : TransactionObserverType { } func databaseDidCommit(db: Database) { - // Extract the names of changed tables, and reset until - // next database event: - let notifiedChangedTableNames = changedTableNames - changedTableNames = [] + // Extract the names of changed tables, and reset until next + // database event: + let changedTableNames = self.changedTableNames + self.changedTableNames = [] // Notify dispatch_async(dispatch_get_main_queue()) { NSNotificationCenter.defaultCenter().postNotificationName( - "DatabaseDidChangeNotification", + DatabaseTablesDidChangeNotification, object: self, - userInfo: ["ChangedTableNames": notifiedChangedTableNames]) + userInfo: [ChangedTableNamesKey: changedTableNames]) } } func databaseDidRollback(db: Database) { - // Forget the names of changed tables: - changedTableNames = [] + // Reset until next database event: + self.changedTableNames = [] } } ```