Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed May 6, 2013
1 parent 7796e2d commit 5656881
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ There is a lot of boilerplate code required to write a Core Data application. Th
* Reflection
* Easy creating and deleting

### SSManagedObjectContextObserver
### SSRemoteManagedObject

* Observe inserted and updated objects in a context
* Easily find or create objects by a remote ID
* Unpack `NSDictionary`'s into your Core Data object's attributes

### SSManagedObjectContext
## Example

* Adds hooks for SSManagedObjectContextObserver
This is very simple example of how to use SSRemoteManagedObject.

## Using the Context Observer
Post.m

You can use `SSManagedObjectContextObserver` to observe when any object is inserted or updated in a context. You can optionally filter this by setting its `entity` property.
``` objective-c
- (void)unpackDictionary:(NSDictionary *)dictionary {
[super unpackDictionary:dictionary];
self.title = dictionary[@"title"];
}
```

Example: (`Photo` is a subclass of `SSManagedObject`)
Now you can create and find posts easily.

``` objective-c
SSManagedObjectContextObserver *observer = [[SSManagedObjectContextObserver alloc] init];
observer.entity = [Photo entityDescription];
observer.observationBlock = ^(NSSet *insertedObjects, NSSet *updatedObjects) {
NSLog(@"Inserted %i photos. Updated %i photos.", insertedObjects.count, updatedObjects.count);
};
[[SSManagedObject mainContext] addObjectObserver:observer];
[observer release];
Post *post = [Post objectWithDictionary:@{@"id": @(1), @"title": @"Hello World"}];
Post *anotherPost = [Post objectWithRemoteID:@(1)];
NSLog(@"Equal: %i", [post isEqual:anotherPost]); // Equal: 1
```
The `observationBlock` will be handed sets of `NSManagedObjectID`s for the inserted and updated objects after a save completes on the observed context. This is handy if you need to do background processing on large sets of changing objects.
If you need to observe deletes, modify an object before save, get objects ordering, etc, you should use the hooks in `NSManagedObject` or use `NSFetchedResultsController`.
For a more complete example, see [CheddarKit](https://github.com/nothingmagical/cheddarkit) which is used in [Cheddar for iOS](https://github.com/nothingmagical/cheddar-ios) and [Cheddar for Mac](https://github.com/nothingmagical/cheddar-mac).

0 comments on commit 5656881

Please sign in to comment.