Nasenbaer
Nasenbaer

Reputation: 4900

Using of subfolders does not work with pathForResource nor URLforResource

I read some items and was happy to find how to add real subfolders But none of any solutions let me see my files in subfolders. All is returning nil.

Path problems with XCode

inDirectory

I've tried pathForResource and URLforResource and inDirectory methodes.

        //NSString *W = [[NSBundle mainBundle] pathForResource:@"LS_ADINFO_0000_LFSB" ofType:@"xml" inDirectory:@"/2012-03-08%20(Published%20as%2008%20MAR%202012)/AERODROMES/LFSB/"];
        //urlPDF = [NSURL URLWithString:W];
        // DEBUG output: urlPDF = nil

        //urlPDF = [[NSBundle mainBundle] URLForResource:@"LFSB/LS_ADINFO_0000_LFSB.xml" withExtension:nil]; 
        // DEBUG output: urlPDF = nil


        //urlPDF = [[NSBundle mainBundle] URLForResource:@"LS_ADINFO_0000_LFSB.xml" withExtension:nil]; 
        // DEBUG output: urlPDF = file://localhost/Users/siri/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/1F5953CD-1E13-40D4-9497-8313F9DDEA77/SwissVfrm03.app/LS_ADINFO_0000_LFSB.xml

How to setup a subdirectory in XCode for accessing in iPad App?

Upvotes: 1

Views: 2617

Answers (2)

Nicolas Miari
Nicolas Miari

Reputation: 16246

I had a curious issue with -pathForResource:ofType:inDirectory:.

Eventhough my resource files' directory structure was faithfully preserved in the final build (I checked this by building the app for Simulator and inspecting the app bundle's contents, in Finder), it would return a non-nil (but erroneous) path that was such as if the target file was residing at the root of the app bundle.

For example,

The file is located at:

.../MyApp.app/Subdir1/Subdir2/file.png

But the following code:

[[NSBundle mainBundle] pathForResource:@"file" ofType:@"png" inDirectory:@"Subdir1/Subdir2"]

...gives instead:

.../MyApp.app/file.png

Changing all directory names to ASCII characters fixed the problem.

Upvotes: 0

Magnetoz
Magnetoz

Reputation: 240

In an iOS application, nonlocalized resources are located at the top-level of the bundle directory. You could create a custom bundle by path, but by default all resources are located at the top level of your bundle regardless of what directories you have set up in Xcode.

iOS Bundle Programming Guide

Upvotes: 6

Related Questions