views:

79

answers:

2

Hi I am currently trying to building a reader app for the iphone, a bit like NYTimes iphone app or Time magazine or USA today iphone app. Basically I'll be parsing a feed containing articles, saving the data locally in a database and displaying stuff and all that.

Now I am just starting off with Iphone app development, I would just like to know what is the best way to manage Images in these sort of apps. Id like to save the images for each article locally. Which is the preferred method for doing so, saving it into a database or saving it to the file system. There are a lot of images and managing them would be easier if i store it in a blob field in the database, but that would affect performance dramatically I guess. Saving it into the filesystem, in the application documents directory would give me better performance but I am wondering how would I manage a large amount of file (Saving it, keeping track of an Image of a particular article, deleting files etc)

A: 

Core Data is probably the best solution for you. Dealing with the FS(File System) would be a bit messy.

Search Apple's docs for Core Data and you'll get all the info you need.

Brad Goss
Agreed, also regarding performance, I changed a project from FS to CoreData for media storage, and I didn't see any slowdown.
NWCoder
+2  A: 

From the Core Data Programming Guide:

It is better, however, if you are able to store BLOBs as resources on the filesystem, and to maintain links (such as URLs or paths) to those resources. You can then load a BLOB as and when necessary.

The idea is to load images lazily, only when they need to appear on screen. This is very important on the device.

Consider how many managed objects will be in memory at once. When the objects are instantiated, if you have the image saved as part of the object, it will be loaded into memory as well and will remain in memory until the object is turned into a fault.

As for the second part of your question on how to ensure that files are removed when managed objects are deleted, register for NSManagedObjectContextObjectsDidChangeNotification and NSManagedObjectContextDidSaveNotification and clean up the files that you can obtain from the objects in NSDeletedObjectsKey and NSUpdatedObjectsKey.

falconcreek