Question

New to Mac console applications. Never done it before, but I want to code with Objective-C, so I chose "Foundation" while creating the application with Xcode.

int main(int argc, const char * argv[])
{

    @autoreleasepool {

        NSString *contentPath = [[NSBundle mainBundle] pathForResource:@"Input" ofType:@"txt"];
        NSLog(@"%@",contentPath);

    }
    return 0;
}

The path is null.

I followed an answer here: https://stackoverflow.com/a/7835776/555690 from a related question, but it did not fix it.

Then I took a look at Getting a nil path from NSBundle, but the problem they have was a directory (I don't have directories - I just placed my file in the project's root).

Why else could I be getting null for this file's path?

Was it helpful?

Solution 2

It's coming up null because typically when you have an .app with bundled resources you would need to add a file named Input.txt into your Supporting Files folder, or Resources folder. Since you're writing a console application I don't understand why you would being do that.

Before adding Input.txt to Supporting Files:

2013-05-09 19:23:40.228 tester[2847:303] (null)

After adding Input.txt to Supporting Files:

2013-05-09 19:21:00.306 tester[2807:303] /Developer/Xcode/DerivedData/tester-gjrofdlcblvmplbjdvvfhieiymzh/Build/Products/Debug/tester.app/Contents/Resources/Input.txt

OTHER TIPS

Your application doesn't have a bundle (which is a specially structured directory), so bundle resource lookups will not look anything up for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top