Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:31:37+00:00 2026-06-01T10:31:37+00:00

I am having trouble saving a photo into core data. I am trying to

  • 0

I am having trouble saving a photo into core data. I am trying to save it as an attribute set to ‘Transformable’ in an Entity. I have seen various discussions on this on SO and the consensus seems to be that in iOS5 and above, I don’t need to use a coder as UIImage now conforms to NSCoding. I am getting an error when I try and save Core Data. Please see below the code I am using to save the photo…

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage, *editedImage, *imageToSave;

    // Handle a still image capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {

        editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
        originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];

        if (editedImage) {
            imageToSave = editedImage;
        } else {
            imageToSave = originalImage;
        }

        // Convert image to Data for entry into Core Data
        NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSave)];

        // Add image to Core Data
        myEntity.attribute = imageData;

        NSError *error = nil;
        if (![managedObjectContext save:&error]) {
            NSLog(@"Error when saving core data");
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }

    }

    [[picker parentViewController] dismissModalViewControllerAnimated: YES];
    [picker release];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:31:38+00:00Added an answer on June 1, 2026 at 10:31 am

    I have done this many times. Change the storage type from transformable to Binary Data and you should be fine.

    You also want to keep a couple of things in mind. If the image is small (1MB or less), there should be no issue storing it in your main entity. If it is larger, you should have the image stored in an entity by itself for performance reasons. If the image is very large, you may want to consider storing it off in the documents directory like anonymous suggests above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble saving an entity into an SQL Server 2005 database. I'm using
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I'm having trouble in saving a m2m data, containing a 'through' class table. I
I'm having some trouble saving some data after using PHP's simplexml_load_file function. I want
I am having trouble converting an image into bytes and saving it in database.
I'm having trouble saving changes made to my POCO's back into the database. When
I'm trying to build a RSS reader, but I'm having trouble with saving the
I am having trouble saving my entities to the database using EntityFramework. I have
I'm having a little bit of trouble saving data to a database. Basically, I
I having trouble figuring out NSBundle & DocumentDirectory data, I have a Camera Picture

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.