-1

I need to save an image picked by an image picker on disk and than associate it to a managed object.
I want to store the image path in the managed object (imagePath attribute is nsstring) but I don't know how to call the image because it must be always available until user delete the managed object.

I thought to call every image with managed object's ID but I believe that it is too long and it's still temporary when I try to save my image...
How can I call every image for each managed object?

Thank you!

matteodv
  • 3,992
  • 5
  • 39
  • 73

2 Answers2

2

If you are going to store it on disk why not just store it in core data using the Transformable type.

You can shorten the managed object id using something like:

NSString *_id=[[self.objectID URIRepresentation] lastPathComponent];
railwayparade
  • 5,154
  • 1
  • 39
  • 49
  • I actually store my image in core data using the transformable type but it is very very slow... I need something that can be done in background. what will lastPathComponent on the objectID get? and will it work if the objectID is still temporary? – matteodv Dec 08 '11 at 23:27
  • I tried to check this with an if/else struct and it seems to be permanent... When is a managed object temporary? – matteodv Dec 08 '11 at 23:52
1

Using the managed object's ID turned into a file name string is actually ideal since it is guaranteed to be unique. The length of the name is hardly an issue to the file system.

gschandler
  • 3,208
  • 16
  • 16
  • Yes, but can you look at the comment on @railwayparade's answer? Thank you! – matteodv Dec 08 '11 at 23:32
  • It totally depends on the amount of image data you are saving. You can set the use external storage binary data attribute and Core Data will store and track the data as a file once it exceeds a certain size threshold, otherwise it is stored within the database itself. This, of course, leads to larger database files, depending on how many images you are storing. Either way is valid, in my opinion, and it comes down to which gives you most acceptable performance for the effort. – gschandler Dec 09 '11 at 03:24