0

I want to load multiple images when my app starts from a website (i.e. all images in http://hello.com/images/ which are named 1.png, 2.png, 3.png..) , so that the images can be used anywhere in the program without needing to reload them every time I want to access them.

Can I simply create a class that holds a static NSArray and fill it at the beginning, to then create an instance of this class whenever I need the images or is there a better way to do it?

Right now, I am loading the images with the following code:

UIImage *image =[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://hello.com/images/%@.png,item]]]];

I want to make the app as efficient as possible, so I am concerned about the creation of multiple objects making it very demanding.

Thanks

juliensaad
  • 2,019
  • 2
  • 20
  • 27
  • You want to load the images every time your app starts or just the very first time that it starts? Can the images change over time such that 1.png is something today and something else on another day? – GoZoner May 12 '12 at 19:06

1 Answers1

1

You can try downloading the images asynchronously in a separate thread when the application starts and use it later.

Here is the SO question and answer where the poster uses a custom class to download the images in the background asynchronously.

Try this for efficient download of images and UI also will not be blocked.

Community
  • 1
  • 1
Sreeram
  • 3,160
  • 6
  • 33
  • 44