I have the structure like the following in my Xcode project.
I need to read all the images from project and need to store it in array.
I have used the following code from some other StackOverflow posts, but it's not working.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Images"ofType:@""];
NSDirectoryEnumerator *direnum;
direnum = [fileManager enumeratorAtPath: filePath];
imageFolder = [NSMutableArray new];
for(NSString *filename in direnum){
if([[filename pathExtension] isEqualToString:@"png"]){
[imageFolder addObject:filename];
}
}
NSLog(@"Files in the folder %@",imageFolder);
I would appreciate, if any one help me to complete this.
- (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)subpath
will get you the array you want.
NSArray *imagesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Images"];