NSUserDefaults
is loaded completely into memory when it is accessed. This means if you data source contains more than a few items this would be really slow or it could even crash when the phone runs out of memory.
But, when I understand you code correctly you are storing the photos in the camera roll. Therefore you have some kind of URL to the image already (the assetURL
in your code).
For a quick and kind of dirty solution (which I find OK for small amounts of data which does not change often, I use NSCoding
. So you can add the title and the assetURL
into a NSDictionary
and add the dictionary to the array of your data source. Then in dealloc
call
[NSKeyedArchiver archiveRootObject:self.myDataSourceArray toFile:[self pathToFileInDocumentsDirectory]];
In viewDidLoad
you can then get the data back you call:
self.myDataSourceArray = [NSKeyedUnarchiver unarchiveObjectWithFile:[self pathToFileInDocumentsDirectory]];
If the data contains many items or the items are about to change much I tend to use Core Data or Sqlite. How to use those doesn't fit into this answer.