andrewsardone + nsmanagedobjectcontext   7

A Guide to Core Data Concurrency
Straight to the point run down private and main queue NSManagedObjectContexts and two distinct setups for handling syncing between the two via save notifications parent-child relationships. I don't think the two setups are mutually exclusive, and the best setup involves save notifications between a private and main context, and then ad-hoc child contexts off of those two "root" contexts.
coredata  concurrency  nsmanagedobjectcontext  cocoa 
february 2014 by andrewsardone
Mantle pull request to add Core Data adapter by jspahrsummers
This is an awesome feature and an awesome pull request.

I've been interested in [Mantle](https://github.com/github/Mantle) for a while, and this pull request adds in an adapter to handle serialization/deserialization of model object as NSManagedObjects. Now I'm even more interested in Mantle and will probably try to use it in a project.

The pull request is simply a great example of

1. Well organized commits
2. Good documentation
3. Clean and understandable code
coredata  objective-c  nsmanagedobjectcontext  via:github 
may 2013 by andrewsardone
Background Managed Object Context Staggers UI Animation - Stack Overflow
A good thread on staggering UIs hooked up with an NSFetchedResultsController after large imports and saves.

One answer was intriguing because it suggested giving your NSFRC a private queue MOC and handling UI-related delegate methods (e.g., -controllerDidChangeContent:) within a `dispatch_async` that grabs the main queue:

```
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
dispatch_async(dispatch_get_main_queue(), ^{
[tableView beginUpdates];
});
}
```

First, is this legit? It would probably be made easier by another object that wraps all NSFRC operations and exposes a single delegate callback for fetched results changes. Secondly, I take it this NSFRC's private queue MOC is a child or sibling of the MOC handling the large import work – how does the NSFRC's private queue MOC get changes? Should someone be listening for the parent/sibling MOC's changes and forwarding a -performFetch: message to the NSFRC?

I also wonder if this setup could be improved with the private-queue-writer-context outlined here: https://pinboard.in/u:andrewsardone/b:bccf2f671dee
cocoa  coredata  iOS  nsmanagedobjectcontext  nsfetchedresultscontroller  gcd 
march 2013 by andrewsardone
lukeredpath/LRFetchedResultSet · GitHub
From Luke Redpath, this returns an auto-updating set of results from executing a Core Data fetch request.

A category on NSManagedObjectContext provides the LR_executeFetchRequestAndReturnResultSet:error: message which executes the fetch request and returns the resulting objects wrapped in an instance of LRFetchedResultSet.

You can observe changes to the result via a block.
coredata  nsmanagedobjectcontext  cocoa  bindings 
december 2012 by andrewsardone
Multi-Context CoreData | Cocoanetics
Some good demonstrations on using parent-child managed object contexts. The 'Asynchronous Saving' section is particularly interesting. It outlines an approach of parent-child managed object contexts where an NSPrivateQueueConcurrencyType context is used exclusively for writing to disk. This private queue c
This smart approach uncouples the writing into its own private queue and keeps the UI smooth as button.


Simply move the persistent store coordinate to the private writer MOC and make the main MOC (used from your main, UI thread) a child of this

```
// create writer MOC
_privateWriterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[_privateWriterContext setPersistentStoreCoordinator:_persistentStoreCoordinator];

// create main thread MOC
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
_managedObjectContext.parentContext = _privateWriterContext;
```
We now have to do 3 saves for every update: temporary MOC, main UI MOC and for writing it to disk. But just as easy as before we can stack the performBlocks. The user interface stays unblocked during the lengthy database operation (e.g. import of lots of records) as well as when this is written do disk.
cocoa  coredata  nsmanagedobjectcontext  iOS 
september 2012 by andrewsardone

Copy this bookmark:



description:


tags: