Created
March 5, 2012 16:02
-
-
Save dive/1979003 to your computer and use it in GitHub Desktop.
coredata with dispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)saveArrayOfImages:(NSMutableArray *)arrayOfImages | |
{ | |
for (UIImage *imageObject in arrayOfImages) | |
{ | |
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); | |
dispatch_async(backgroundQueue, ^{ | |
NSManagedObjectContext *context = [appDelegate managedObjectContext]; | |
NSData *dataFromImage = UIImagePNGRepresentation(imageObject); | |
NSManagedObject *insertObject = [NSEntityDescription insertNewObjectForEntityForName:@"Images" inManagedObjectContext:context]; | |
[insertObject setValue:dataFromImage forKey:@"image"]; | |
[appDelegate saveContext]; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment