Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
I use code as below to get path in bundle, but I got nil, I am not sure why? can you give me some suggestion?
Code:
-(NSString *) pathInBundle:(NSString *)fullFileName {
	NSString *filename = [fullFileName stringByDeletingPathExtension];
	NSString *ext = [fullFileName pathExtension];
	NSBundle *bundle = [NSBundle mainBundle];
	return [bundle pathForResource:filename ofType:ext];
}
 

Attachments

  • SnapShot 2010-08-29 at 18.23.09.jpg
    SnapShot 2010-08-29 at 18.23.09.jpg
    192.3 KB · Views: 142
  • SnapShot 2010-08-29 at 18.23.22.jpg
    SnapShot 2010-08-29 at 18.23.22.jpg
    183.5 KB · Views: 112
try printing out your filename and extension to the console window to make sure that they are returning the expected values. At a guess maybe your extension is returning dot [extension name] instead of just [extension name]. I'm not sure if the path accepts dot [extension name], i'm sure someone will correct me on this.
 
Apply some basic debugging.

What does it mean when NSBundle pathForResource:eek:fType: returns nil?

1. Start with the NSBundle class reference doc:
http://developer.apple.com/iphone/l...asses/NSBundle_Class/Reference/Reference.html

2. Go to the section describing the method.

3. Read what it says about the Return Value:
Return Value
The full pathname for the resource file or nil if the file could not be located.

From this information, what is the next logical thing to check?

Try confirming that there is a file with the name and extension you asked for.


If there is such a file, then double-check the spelling of the name and extension in your code.

Select a large font size to temporarily make the letters in your source file more obvious.

Use screen zoom to temporarily magnify the debugger window, to temporarily make strings like database.sqliet3 more obvious.


To enable screen zoom:
System Preferences > Universal Access > Seeing tab
Zoom has 2 radio buttons: On Off.
Choose amount of Maximum Zoom using Options... button.
Choose other options, too: smoothing, zoom follows keyboard focus, how the screen image moves, etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.