kylef-archive / KFData

Core Data done right for iOS 5+/OS X 10.7+
http://cocoadocs.org/docsets/KFData/
BSD 2-Clause "Simplified" License
53 stars 7 forks source link

Enable passing in queues for success and failure call blocks #43

Closed calvincestari closed 4 years ago

calvincestari commented 11 years ago

Routinely we're doing something like this:

[[self managedObjectContext] performWriteBlock:^{
    ..persistence code..
} success:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (success) {
            success();
        }
    });
} failure:^(NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^{
        if (failure) {
            failure(error);
        }
    });
}];

Typically this kind of scenario exists in API client code where the client instance has it's own NSManagedObjectContext created with NSPrivateQueueConcurrencyType concurrency. It would be useful to be able to assign a queue for dispatching the success/failure blocks to. We can then avoid having to manually dispatch from the main queue. If no queue is set then we simply call the blocks as normal.