0

In my app bundle, I have several images of several items.

ItemA_largepicture.png

ItemA_smallPicture.png

ItemA_overViewPicture.png

ItemB_largepicture.png

ItemB_smallPicture.png

ItemB_overViewPicture.png

ItemC_largepicture.png

ItemC_smallPicture.png

ItemC_overViewPicture.png

...

I want to extract, for example all ItemB pictures into an array. I can do as Prince suggested

NSString *bundleRootPath = [[NSBundle mainBundle] bundlePath];
NSArray *bundleRootContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRootPath error:nil];
NSArray *files = [bundleRootContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self beginswith 'ItemB'"]];
NSLog(@"%@",files);

This worked very well. The next problem is that all ItemB files is in a folder named ItemB. Somehow I need to add a path within the bundle to the ItemB folder. I thought

NSString *bundleRootPath = [[NSBundle bundleWithPath:@"ItemB"] bundlePath];

was logical, but this didn't work. Can anyone please explain how this works, and how to access the folder?

Tom Tallak Solbu
  • 559
  • 6
  • 20

1 Answers1

1
NSString *bundleRootPath = [[NSBundle mainBundle] bundlePath];
NSString *itemBPath = [bundleRootPath stringByAppendingPathComponent:@"ItemB"];
NSArray *itemBContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:itemBPath error:nil];
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382