Note that there are some explanatory texts on larger screens.

plurals
  1. POGet image paths from NSBundle in Objective C?
    primarykey
    data
    text
    <p>I have about 60 images I want to store in Core Data, 30 of which are avatars and have the prefix of avt_filename_00X.png and 30 of them are smaller and have a different prefix.</p> <p>Rather than storing all the images as BLOBs in Core Data/SQLite, I want to store the paths for each image found (in the same way you would store image paths for a MySQL database).</p> <p>However I am not sure how to grab the path of the image as found in NSBundle.</p> <p>I can get the path to the NSDocumentDirectory via:</p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager fileExistsAtPath:documentsDirectory]; NSLog(@"documentsDirectory = %@", documentsDirectory); </code></pre> <p>And I can load the image and add it to an array.</p> <pre><code>if (qty == 0) { //NSLog(@"fileToLoad = %@", fileToLoad); UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileToLoad ofType:fileExt]]; [self.avtList addObject:img]; [img release]; } else { // load multiple image into an array // not coded yet } </code></pre> <p>But, what I'm unsure of is:</p> <ol> <li><p>How do I grab the path where the computer found the image once its inside the NSBundle?</p></li> <li><p>How can I be sure that the path will work when the app is on a device?</p></li> </ol> <p>The idea would be to get all the images stored in an array and then push them to Core Data/SQLite at a later time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload