Where is a bug when get bundle path?

Discussion in 'iOS Programming' started by mikezang, Aug 29, 2010.

  1. mikezang macrumors 6502a


    May 22, 2010
    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?
    -(NSString *) pathInBundle:(NSString *)fullFileName {
    	NSString *filename = [fullFileName stringByDeletingPathExtension];
    	NSString *ext = [fullFileName pathExtension];
    	NSBundle *bundle = [NSBundle mainBundle];
    	return [bundle pathForResource:filename ofType:ext];

    Attached Files:

  2. donaghy macrumors member

    Aug 6, 2009
    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.
  3. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Apply some basic debugging.

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

    1. Start with the NSBundle class reference doc:

    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.
  4. mikezang thread starter macrumors 6502a


    May 22, 2010
    Tokyo, Japan

Share This Page