tom*_*ing 5 macos xcode objective-c
我正在开发一个OSX应用程序,在其中,我想知道当前目录是什么(即保存.app-file的目录).
目前,我正在使用以下代码:
NSString *dir=[[NSFileManager defaultManager] currentDirectoryPath];
[[NSAlert alertWithMessageText:@"dir"
defaultButton:@"OK"
alternateButton:nil
otherButton:nil
informativeTextWithFormat:dir] runModal];
Run Code Online (Sandbox Code Playgroud)
当从Xcode(运行按钮)运行时,这给了我调试目录(这是我正在寻找的),但是当在Finder中双击应用程序时(因此,在调试目录中),它给了我/哪些谜题我.
为什么会发生这种情况?如何可靠地获取当前目录?
那是包文件夹:
NSString *appPath = [[NSBundle mainBundle] bundlePath];
Run Code Online (Sandbox Code Playgroud)
(参考).