Depending on how large your images are, you can let the new βuse external storageβ attribute do this for you. Here is an explanation that it copies from my other answer:
Since we are now on IO5, you no longer need to write images to disk. Now you can set "allow external storage" to the coredata binary attribute. According to the notes on the release of apples, this means the following:
Small data values, such as thumbnails of images, can be effectively stored in databases, but large photographs or other materials are best handled directly by the file system. Now you can specify that the value of the managed attribute of the object can be saved as an external record - see setAllowsExternalBinaryDataStorage: when enabled, the Basic data heuristically decides on the basis of value if it should save the data directly in the database or store the URI in a separate file that it manages for you. You cannot query data based on the contents of the binary if you use this option.
There are several advantages to using this approach. The first copy saves the files at least as fast as you could when writing to the file system. But if there are small images that apply to the conditions described above, it will be much faster, because they will be saved directly in the sqlite coredata file.
In addition to iOS 5, itβs very easy to work with individual managed contexts and make changes to the child context in the background. If you have completed successfully, you can combine this child context into your main managed object context and perform the necessary processing.
[child performBlock:^{ [childsave:&parentError]; //do this in background on child context }];
There is an NSPrivateQueueConcurrentType file for creating a "child-moc" - see [documentation for the box] [1]
And at least you can work with coredata objects that allow you to cache, limit, and optimize further processing after the download is complete.
[1]: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html#//apple_ref/doc/uid/TP40003385 for more information
source share