Skip to content

Instantly share code, notes, and snippets.

View lemonkey's full-sized avatar
🏠
Working from home

Ari Braginsky lemonkey

🏠
Working from home
View GitHub Profile
@lemonkey
lemonkey / fetchThingsWithCompletion.m
Created October 28, 2016 01:13 — forked from quellish/fetchThingsWithCompletion.m
Pseudo-sample of a core data fetch with a completion block.
- (void) fetchThingsWithCompletion:(void (^)(NSArray *, NSError *))completion{
[context performBlock:^{
result = [context executeFetch:...
if (completion != nil){
completion(result, error);
}
}];
}
@lemonkey
lemonkey / waitForBlock.m
Created October 28, 2016 01:14 — forked from quellish/waitForBlock.m
Pseudo-sample of synchronous use of Core Data performBlock: using dispatch group
group = dispatch_group_create();
dispatch_group_enter(group);
[context performBlock:^{
result = [context executeFetch:...
dispatch_group_leave(group);
}];
groupResult = dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
@lemonkey
lemonkey / saveManagedObjectContext.m
Created October 28, 2016 01:17 — forked from quellish/saveManagedObjectContext.m
Recursive save of managed object context
- (void) saveManagedObjectContext:(NSManagedObjectContext *)managedObjectContext withCompletion::(void (^)(BOOL, NSError *))completio{
managedObjectContext performBlock:^{
NSError *error = nil;
if (![managedObjectContext save:&error]){
completion(NO, error);
} else {
if ([managedObjectContext parentContext] != nil){
[self saveManagedObjectContext:[managedObjectContext parentContext] withCompletion:completion];
} else {
@lemonkey
lemonkey / allPeopleInManagedObjectContext.m
Created October 28, 2016 18:13 — forked from quellish/allPeopleInManagedObjectContext.m
allPeopleInManagedObjectContext
- (void) allPeopleInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext withCompletion:(void (^)(NSArray*, NSError*))completion {
[managedObjectContext performBlock:^{
NSError *error = nil;
NSArray *results = nil;
NSFetchRequest *fetchRequest = nil;
NSPredicate *predicate = nil;
NSEntityDescription *entity = nil;
fetchRequest = [[NSFetchRequest alloc] init];
entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
@lemonkey
lemonkey / save.m
Created October 28, 2016 18:14 — forked from quellish/save.m
Save
[managedObjectContext performBlock:^{
NSError *error = nil;
if (![managedObjectContext save:&error]){
[self handleError:error];
}
}];
@lemonkey
lemonkey / property.m
Created October 28, 2016 18:14 — forked from quellish/property.m
Managed object property access
[[managedObject managedObjectContext] performBlock:^{
NSString *value = [managedObject someValue];
[NSOperationQueue mainQueue] addOperationWithBlock:^{
[[self label] setText:value];
}];
}];