Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing all images in a folder iphone Application

I am making an iPhone app using Xcode and following is the directory structure

GFGGAME
  -gfggame.xcodeproj
  -Images
    --bagold
     ---bags_1.png
     ---bags_2.png
    --bagsnew
     ---bags_5.png
     ---bags_6.png

I want to access all images from folder bagsold and bagsnew . If I use resource path and a predicate filter for png it gives me all the png files . Is there a way i can access just the files present in the folder.

like image 916
ila Avatar asked Jan 15 '23 14:01

ila


1 Answers

I think you probably want to use this NSBundle method:

+ (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)bundlePath

See API docs here

You would pass @".png" as your extension, and then specify the directory path just for the subdirectories you want (you might need to call this twice, one for each subdirectory, and then just append the second array of paths to the first).

See a similar question on Stack Overflow here

Note the point in the answer (link) above, about what you need to do in Xcode to make this work.

like image 85
Nate Avatar answered Jan 28 '23 06:01

Nate