I'm working on my small project which take pictures and save them, very simple, using Core Data. I have two entities; one is 'Person' and the other is 'Image'. the relationship from Person to Image is to-many and from Image to Person I got inverse relationship as well.
All I need at the moment is to add multiple number of images (taken from iphone camera or chosen from library) to one Person entity.
I'd like to know whether there is any kind of sample code that deals with to-many relationship with UIImage using Core Data.
many thanks.
=====================
Actually I wish I could specify the problem. What i'm trying to do is using access methods that are given for free in to-many relationship to add object such as
- (void)addPersonImageObject:(PersonImage *)value;
and also I've implemented methods related to ImageToDataTransformer.
I spent almost a week on this matter and I think I need a guiding sample code that I can study first for my add project.
Images from the camera could be really big. General rule to images in Core Data is below 1 MB. You might want to store the image in a directory and store the path in Core Data.
Besides converting the
UIImage
toNSData
and back there is nothing special by having a to-many relationship withUIImage
s. So any core data tutorial that includes a to-many relationship should suffice. If you need sample code you can check out Apple's iPhoneCoreDataRecipes.A few pointers to help you get started. Let's pretend we have a
PersonViewController
that inherits from a `UITableViewController' that gets called with something like:PersonViewController has the following properties:
There is add button which would shod the image picker
Then in the callback
imagePickerController:didFinishPickingMediaWithInfo:
we can:The implementation of
images
just to keep it simpleThe table view data source methods would just be:
and however the cell is created doesn't really matter. At then if we wanted to do something with the images we can do something in
tableView:didSelectRowAtIndexPath: