I'm developing an OSX-application and in it, I'd like to know what the current directory is (ie the directory which holds .app-file).
At the moment, I'm using the following code:
NSString *dir=[[NSFileManager defaultManager] currentDirectoryPath];
[[NSAlert alertWithMessageText:@"dir"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:dir] runModal];
When running from Xcode (Run-button), this gives me the debug directory (which is what I'm looking for), but when double-clicking the app in Finder (so, in the debug directory), it's giving me /
which puzzles me.
Why does this happen and how can I get the current directory reliably?
在Apple Swift中编程时,您将获得以下应用程序路径:
let pathtoapplication: String = NSBundle.mainBundle().bundlePath
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.