What is the path to the Mac OSX application content folder

I am writing an Objective-c ++ application and I am trying to get to the Contents application folder.

Suppose my application name is MyApp.app. If I run the application from Xcode, I can get to the Contents folder as follows:

 std::fstream file; file.open("MyApp.app/Contents/some_text_file.txt"); if(file.is_open()) { ... } else { ... } 

But if I run my embedded application without Xcode, then file.is_open() will fail.

0
source share
2 answers

[[NSBundle mainBundle] bundlePath] will provide you with the path to the MyApp.app directory. You can then add Contents to this path.

Alternatively, [[NSBundle mainBundle] resourcePath] will provide you with the path to the MyApp.app/Contents/Resources directory. Then you can remove the subdirectory from this path; see Working with paths from [[NSBundle mainBundle] resourcePath]

+3
source

Use the NSBundle class to get information about your application. [[NSBundle mainBundle] bundlePath] gives you the full path to MyApp.app.

+2
source

Source: https://habr.com/ru/post/1482315/


All Articles