7

Have the folder structure like

*Resources/books/CD_en/icon/0.jpg;
*Resources/books/CD_en/icon/1.jpg;
*Resources/books/DD_en/icon/0.jpg;
*Resources/books/DD_en/icon/1.jpg;

how to get resource path from NSBundle using the subpath 'books/CD_en/icon/0.jpg'

I tried using,

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)subpath

[[NSBundle mainBundle] pathForResource:@"0.jpg" ofType:@"jpg" inDirectory:@"books/CD_en/icon"];

but it returns nil.

Regexident
  • 29,441
  • 10
  • 93
  • 100
Suresh Thayu
  • 2,132
  • 1
  • 13
  • 8
  • I think yehnan has it -- your name should be 0 and not 0.jpg – RyanWilcox Feb 18 '10 at 03:43
  • [[NSBundle mainBundle] pathForResource:@"0" ofType:@"jpg" inDirectory:@"books/CD_en/icon"]; Wrongly typed... i did as above – Suresh Thayu Feb 18 '10 at 05:31
  • I think the problem is related to this: http://stackoverflow.com/questions/1401338/include-a-resource-directory-hierarchy-into-app-bundle – yehnan Feb 18 '10 at 09:02

2 Answers2

2

I got it. Simply we need the add the folder structure 'books/...' to the app Resource folder. Which will display in blue color.

Then the existing code is running successfully.

Thanks to yehnan.

Suresh Thayu
  • 2,132
  • 1
  • 13
  • 8
1

i got same problem to retrive image from Resource folder. Adding image by following method solved my problem.

  • Right click on project in xcode and select Add Files to "project name".
  • Select your image file from computer local disk.
  • In the pop-up window make sure you select Copy items into destination group's folder and Create Folder References for any added folders and Add to targets.
  • click Add.

Then with bellow code i can retrive my image.

[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"png"];
Bhavin_m
  • 2,746
  • 3
  • 30
  • 49