0

I am building an iOS app and I would like to persist images. The images I persist have the potential to be in the thousands? I have read online that a common solution is to use the Documents/ directory.

Is storing in the Documents/ directory a good approach even if the size of the images and number of images can be quite large (order of thousands think between 1,000 - 5,000)? What about NSArchiver, it has the advantage of probably storing the image data in a more compact format. I do not want the overhead of DB/model management framework like Core Data, it is pretty overkill for my use case.

AyBayBay
  • 1,726
  • 4
  • 18
  • 37
  • Just out of curiosity - do you absolutely have to store them locally? Is cloud storage an option? AWS (Amazon Web Services) is fantastic for this, and is incredibly fast, although has somewhat of a learning curve. Apple's CloudKit is also an option that's easier to learn. The only reason I ask is that storing thousands of images on the user's device could eat up a huge chunk of their storage, and isn't very practical. – Pierce Jan 09 '17 at 01:59
  • I am open to using something like Apple's CloudKit, how does that perform? But is storing thousands of images locally uncommon? I have to think other image-heavy apps do it. If I use NSArchiver will the memory foot-print reduce? What if I used an actual persistent store/DB? – AyBayBay Jan 09 '17 at 02:02
  • You can not store the images in "Document" folder. As per Apple guidelines, the data which can be downloaded from server again need to store in "Library/Cache" folder. Also there should be some user interaction to store data in "Documents" folder. You cannot store data in "Documents" folder without user knowing it. Because "Document" folder is backup to Cloud. – miOS Jan 09 '17 at 09:09
  • @AyBayBay - Sorry for the delayed response. You know I would imagine that most larger apps would still use some sort of cloud storage. Unless you're talking about some really small clip-art images, a thousand of images is just too much. I think the average size of an image file taken with the camera on my phone is almost 8mb. You can add every image you need in your `xcassets`, and they'll be cached. – Pierce Jan 09 '17 at 22:25
  • @AyBayBay - CloudKit works just like any other cloud computing service, but it's very easy to use. As far as images go with CloudKit, you convert your `UIImage` to `Data`, and then cast the data as a `CKAsset` (CloudKit Asset), you save the asset to a `CKRecord` object, and then at any given time you can fetch that `CKRecord`, and grab the asset back out of it, and then convert it back to a `UIImage` to display in your UI. – Pierce Jan 09 '17 at 22:29

0 Answers0