views:

58

answers:

2

Let's say I've got a folder in my project with bunch of png files in it (or mp3 files, or mov files etc).

I would like to create an NSArray populated with the items within that folder... for instance an array of UIImages for the folder of images (or just an array of NSStrings of the image name).

Is this possible? I know I could create a plist with all the names in, or name the items individually within the code, but this would break the DRY (don't repeat yourself) rule. Has anyone worked this out?

+4  A: 

Try NSFileManager's

- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error
phooze
+1  A: 

Or, if your resources are in the app bundle, use -[NSBundle pathsForResourcesOfType:inDirectory:] as in

 NSArray* mp3s=[[NSBundle mainBundle] pathsForResourcesOfType:@"mp3" inDirectory:nil];

Passing nil to the directory parameter defaults to the top level in the app bundle on iPhone, Resources/ in the OS X.

Yuji