Skip to content

Instantly share code, notes, and snippets.

@dive
Created March 5, 2012 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dive/1979003 to your computer and use it in GitHub Desktop.
Save dive/1979003 to your computer and use it in GitHub Desktop.
coredata with dispatch
- (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