繁体   English   中英

Objective-C(OSX)中的程序目录

[英]Program directory in Objective-C (OSX)

我正在开发一个OSX应用程序,在其中,我想知道当前目录是什么(即保存.app-file的目录)。

目前,我正在使用以下代码:

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

当从Xcode(运行按钮)运行时,这给了我调试目录(这我正在寻找的),但是当在Finder中双击应用程序时(因此,在调试目录中),它给了我/哪个困惑我

为什么会发生这种情况?如何可靠地获取当前目录?

那是包文件夹:

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

参考 )。

在Apple Swift中编程时,您将获得以下应用程序路径:

let pathtoapplication: String = NSBundle.mainBundle().bundlePath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM