Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
What is the best way to show images on an app?

Currently we download from our DB via base 64 and store it in core data, which makes scrolling down the collections view of products a long time.

I don't believe we need to save to core data, because internet speeds are efficient these days and because i don't really see a need to save tons of images (if the user is view many products in one sitting) to the device. Also I don't believe many users will think of going on any type of B2C app offline, considering it won't show the latest prices and inventory.

I'm thinking if we are able to draw the image from a URL. Please suggest would you guys would do in my situation.
 

dantastic

macrumors 6502a
Jan 21, 2011
572
678
You shouldn't store images in a database, databases aren't good at storing images.
If you need to persist the image for a very long time just write the image file to disk, either documents directory or cache directory depending on. You say product images so I'm guessing probably cache directory...

If you're talking small images, cheap to re-download. You should be looking at implementing an image cache using NSCache. You can implement something yourself (my preference) or rely on something like SDWebImage to manage the downloading and caching for you.
 

Dookieman

macrumors 6502
Oct 12, 2009
390
67
What is the best way to show images on an app?

Currently we download from our DB via base 64 and store it in core data, which makes scrolling down the collections view of products a long time.

I don't believe we need to save to core data, because internet speeds are efficient these days and because i don't really see a need to save tons of images (if the user is view many products in one sitting) to the device. Also I don't believe many users will think of going on any type of B2C app offline, considering it won't show the latest prices and inventory.

I'm thinking if we are able to draw the image from a URL. Please suggest would you guys would do in my situation.

Like dantastic mentioned,

Don't save images to Core Data, they are large and will result in very long load times. Write the file to disk and keep a reference to the file name in Core Data. If you don't want to save the images locally, write an asynchronous image downloading tool.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
There will probably always be a lag of 1/4 to 1/2 second or more to download an image so you want to cache it locally. There are a number of image cache libraries you can use. I've used Haneke and FastImageCache. Both work fine. Haneke is simple to integrate. FastImageCache is more code to integrate but probably works better if your images are all the same size.

If your images can be updated on the server then you'll need a slightly different caching strategy than commonly used. First check if the image is in the cache and use it if it's found. Then always download the image from the server and use the new copy. This will both use the speed of the cache and update the file if it needs it.
 

AxoNeuron

macrumors 65816
Apr 22, 2012
1,251
855
The Left Coast
Wow. Yeah, storing images in Core Data is a VERY bad idea. You should really be writing them to the local filesystem in a folder somewhere.
 

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
Ok, got it. We have a general senior developer that was pushing usto do this without doing proper research. Finally your replies had convinced him.

We do have another app that users need to take orders offline, we use core data to store those images of the products. Is that the best solution?
 

AxoNeuron

macrumors 65816
Apr 22, 2012
1,251
855
The Left Coast
Ok, got it. We have a general senior developer that was pushing usto do this without doing proper research. Finally your replies had convinced him.

We do have another app that users need to take orders offline, we use core data to store those images of the products. Is that the best solution?
Dear god, no!!!!!! Stop storing images in Core Data!!! It requires a lot of extra work that the device shouldn't have to do just to retrieve an image. There are much more optimized solutions that are not only faster, but also much easier.

Core Data is meant for much smaller bits of data.

What you should do instead is just store a reference to the image in Core Data. I usually just use the filename.

In most of my apps, I store images as URL's to the online path of the image. But I also build a local cache of the most commonly accessed images. If my app is ever about to download an image, it first checks to see if the image is already in the cache. My apps automatically save the most commonly accessed images to disk, a background process cleans up rarely accessed images. This is both extremely fast and storage efficient. It's actually very similar in concept to how iOS handles memory management via automatic reference counting.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.