title: Why is saving these images to core data taking 17 sec + on the iPhone?
body: <p>I have been working with Apple's iPhone CoreDateRecipes sample code to learn more about tableviews and core data. I have coded my own test app based off of that sample, and it works well except for one thing. When I choose a photo for the 'recipe', no matter if it is from the camera or the library, when I hit "Done" to leave editing mode, it takes about 15 seconds before returning control to the user. This happens when testing on the device - in simulator, there is still a delay, but it is only 2-4 seconds.</p>
  
  <p>I tested the "edit/done" button without choosing a photo and editing other data, and it saves instantaneously, so I'm pretty sure the image is to blame. Below is the code where it leaves editing mode, and the image processing code - what can I add/change/remove to speed this up? I know these sample code pieces are just proofs of concept, but I can't believe they published an example with such a crappy user experience!</p>
  
  <p>Thanks, as always, for any guidance...let me know if there is any other code you need to see, or <a href="http://developer.apple.com/IPhone/library/samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html" rel="nofollow noreferrer">you can see the whole sample project here</a></p>
  
  <pre><code>- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
      [super setEditing:editing animated:animated];
      [self updatePhotoButton];
  
      nameTextField.enabled = editing;
      overviewTextField.enabled = editing;
  
      [self.navigationItem setHidesBackButton:editing animated:YES];
  
  
      if (!editing) {
          NSManagedObjectContext *context = recipe.managedObjectContext;
          NSError *error = nil;
          if (![context save:&amp;error]) {
              NSLog(@"Error in RecipeDetailViewController:setEditing -- %@, %@",error, [error userInfo]);
              abort();
          }
      }
  }
  
  
  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
  
      NSManagedObject *oldImage = recipe.image;
      if (oldImage != nil) {
          [recipe.managedObjectContext deleteObject:oldImage];
      }
  
      NSManagedObject *image = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:recipe.managedObjectContext];
      recipe.image = image;
  
      [image setValue:selectedImage forKey:@"image"];
      CGSize size = selectedImage.size;
      CGFloat ratio = 0;
      if (size.width &gt; size.height) {
          ratio = 70.0 / size.width;
      } else {
          ratio = 70.0 / size.height;
      }
  
      CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height);
  
      UIGraphicsBeginImageContext(rect.size);
      [selectedImage drawInRect:rect];
      recipe.thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
  
      [self dismissModalViewControllerAnimated:YES];
  }
  </code></pre>