Amit Battan
Amit Battan

Reputation: 3018

How add thousands of images in iphone project

I have to add thousands of images in my iphone project.

What is best way to flow for it?

I think putting images into bundle is not a good way.

Please suggest me

Amit Battan

Upvotes: 1

Views: 229

Answers (2)

sergio
sergio

Reputation: 69027

You have two options, IMO: either you store the images in the app bundle, or you download them from a website.

I don't see any problems with storing the images in the bundle. The bundle will be larger and take time to download (and it will be downloadable only via WIFI, not 3G). There are many apps around whose bundle is 200+MB...

if you have some NSData (say, downloaded through NSURLConnection) that you want to store to the documents folder, do:

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
 NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory 
 NSString *filePath = [documentsPath stringByAppendingPathComponent:@"filname.ext"];
 [nsData writeToFile:filePath atomically:YES]; //Write the file

For a way to store to sqlite, see this S.O. article. Anyway, as I said in a comment, I would not see much sense to it; you don't use a DB to store file, that's what a file system is meant for; you use a DB to store data that you want to search, sort, join, etc... Anywau, it could be ok to store in sqlite the paths to the images.

Upvotes: 3

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73608

How big are those images? If they are too big, it's not advisable to put all of them in bundle. As you dont want to have a big binary just cause of the images!

Maybe you can stream (through HTTP) the images on demand...

Upvotes: 0

Related Questions