Skip to content

Commit

Permalink
Add note about Swift and NSNotificationCenter
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Dec 13, 2015
1 parent a5dd9d0 commit aa5a467
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ For example a author can have many documents and a document can have many author
Logging changes to Core Data is quite simple, just subscribe to changes like this and print the needed elements:

```objc
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(changeNotification:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.dataStack.mainContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(changeNotification:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.dataStack.mainContext];

- (void)changeNotification:(NSNotification *)notification {
NSSet *deletedObjects = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
Expand All @@ -421,6 +421,8 @@ Logging changes to Core Data is quite simple, just subscribe to changes like thi

Logging updates is a bit more complicated since this changes don't get propagated to the main context. But if you want an example on how to do this, you can check the AppNet example, [the change notifications demo is in the Networking file](https://github.com/hyperoslo/Sync/blob/master/AppNet/Networking.swift#L27-L57).

If you're using Swift to be able to use `NSNotificationCenter` your class should be a subclass of `NSObject` or similar.

#### Crash on NSParameterAssert

This means that the local primary key was not found, Sync uses `remoteID` by default, but if you have another local primary key make sure to mark it with `"hyper.isPrimaryKey" : "YES"` in your attribute's user info. For more information check the [Primary Key](https://github.com/hyperoslo/Sync#primary-key) section.
Expand Down

0 comments on commit aa5a467

Please sign in to comment.