3

I'm new to Core Data and I'm working on my first personal iOS app.

I have an entity, lets call it Car, which has a thumbail as well as a gallery of other images associated with it. The data is synced to an online service using ASIHTTPRequest and JSONKit. The app doesn't need to create new Car's, just display them.

The thumbnail could be around 100kB so I may store that as blob data within the Car entity.

However I'm not sure how I should store the other multiple images?

The images would be around 800kB to 1MB each using so storing them in the Core Data store doesn't seem to be recommended.

The only options I can think of are:

  • Store the url of each photo within another entity CarImage and rely on ASIHTTPRequest's cache.
  • Create a folder structure and save each image into it's corresponding Car's folder and keep references to the file path in the CarImage entity

Because the data is synced, there is the potential for Car's to be deleted, so images in folders would have to be deleted as well. I can see this getting out of hand pretty quickly.

I would appreciate any advice. Thanks.

Ben
  • 1,382
  • 10
  • 14
  • [This Question](http://stackoverflow.com/questions/4158286/storing-images-in-core-data) is almost the same. – Ben Apr 12 '11 at 11:28
  • I should mention that there could be over 1000 `Car`s each with 4-5 images. – Ben Apr 13 '11 at 03:50

2 Answers2

1

I'd take your first option.

Regarding the images that would have to be deleted: isn't that taken care of automatically by ASIHTTPRequest's cache, once they expire? At least that's what I'd expect from a cache...

André Morujão
  • 6,963
  • 6
  • 31
  • 41
  • Yes ASIHTTPRequest would deal with that if I go with the first option. – Ben Apr 13 '11 at 03:49
  • I'm going to accept this answer (as it was the first one) even thou they're both the same pretty much. Thanks guys – Ben Jul 12 '11 at 09:41
1

I'd go with the first option. I've done something similar in the past, though I actually did store the image binary data in Core Data as well. I wouldn't recommend storing the data, though, as this caused problems for me - just rely on ASIHTTPRequest's cache.

Josh Brown
  • 52,385
  • 10
  • 54
  • 80