Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources folder path in cocoa app

I am working on Mac OS X app which using some c files, and i have a configuration file i add it to the app resources.

My question is "What is the relative path of resources folder?"

I tried

"[MyAppName].app/Contents/Resources/config.cfg"

and it works fine only when I run my app from xCode, otherwise it's doesn't work!

I thought the app starts from "MacOS" folder, so i used this path: "../Resources/config.cfg"

but it also didn't work :(

any help please

like image 367
Ahmed Khalaf Avatar asked Nov 10 '13 11:11

Ahmed Khalaf


1 Answers

Using relative paths is asking for trouble. Fortunately Cocoa will give you an absolute path:

NSBundle *myBundle = [NSBundle mainBundle];
NSString *absPath= [myBundle pathForResource:@"config" ofType:@"cfg"];
like image 141
mah Avatar answered Sep 26 '22 02:09

mah