Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all images in the project folder that start with a specific string

I am quite new in iOS development and Objective-C and I would appreciate some help.

I created a Group folder in Xcode where I placed all my images. All my images are inside the project folder.

I want to iterate through the Xcode folder routineIcons and get all Images that have b- in their name and put their name and extension into an array.

Could anyone point me in the right direction on how to do this? bah.. is it possible??

enter image description here

like image 519
Jonathan Thurft Avatar asked May 05 '13 23:05

Jonathan Thurft


2 Answers

You can use this snipped:

 NSMutableArray *result = [NSMutableArray array];
 [[[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil] enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
    NSString *path = [obj lastPathComponent];
    if ([path hasPrefix:@"b-"]) {
        [result addObject:path];
    }
}];
like image 127
Victor Avatar answered Nov 17 '22 00:11

Victor


At runtime, the routineIcons folder won't exist. All of those images, along with all other resources, will end up in the app's resource bundle.

What you can do is get the path to the resource bundle then use NSFileManager to get all of the files in the folder. You can then ignore any that don't start with "b-".

like image 2
rmaddy Avatar answered Nov 17 '22 02:11

rmaddy