objective c - Console application - NSBundle can't get file path -


new mac console applications. never done before, want code objective-c, chose "foundation" while creating application xcode.

int main(int argc, const char * argv[]) {      @autoreleasepool {          nsstring *contentpath = [[nsbundle mainbundle] pathforresource:@"input" oftype:@"txt"];         nslog(@"%@",contentpath);      }     return 0; } 

the path null.

i followed answer here: https://stackoverflow.com/a/7835776/555690 related question, did not fix it.

then took @ getting nil path nsbundle, problem have directory (i don't have directories - placed file in project's root).

why else getting null file's path?

it's coming null because typically when have .app bundled resources need add file named input.txt supporting files folder, or resources folder. since you're writing console application don't understand why being that.

before adding input.txt supporting files:

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

after adding input.txt 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 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -