Program Catalog in Objective-C (OSX)

I am developing an OSX application and in it I want to know what the current directory is (i.e. the directory containing the .app file).

I am currently using the following code:

NSString *dir=[[NSFileManager defaultManager] currentDirectoryPath];
[[NSAlert alertWithMessageText:@"dir"
                 defaultButton:@"OK"
               alternateButton:nil
                   otherButton:nil
     informativeTextWithFormat:dir] runModal];

When launched from Xcode (Run-button), this gives me a debug directory (which is exactly what I'm looking for), but when I double-click the application in the Finder (so, in the debug directory) it gives me /, which puzzles me.

Why is this happening and how can I get the current directory with reliability?

+5
source share
2 answers

This is the package folder:

NSString *appPath = [[NSBundle mainBundle] bundlePath];

( reference ).

+7
source

When programming with Apple Swift, you get the path to the application:

let pathtoapplication: String = NSBundle.mainBundle().bundlePath
+2
source

All Articles