Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用swift获取OS X中.app捆绑包的绝对路径_Swift_Macos - Fatal编程技术网

使用swift获取OS X中.app捆绑包的绝对路径

使用swift获取OS X中.app捆绑包的绝对路径,swift,macos,Swift,Macos,我试图找到一个简单的OSX应用程序运行的路径。我试过了 let fileManager = NSFileManager.defaultManager() let path = fileManager.currentDirectoryPath 但是路径总是有值。如何获取绝对路径,例如,如果从/Users/xxx/sandbox/sample.app执行.app,我期望值/Users/xxx/sandbox 可能吗?使用NSBundle: let path = NSBundle.mainBundl

我试图找到一个简单的OSX应用程序运行的路径。我试过了

let fileManager = NSFileManager.defaultManager()
let path = fileManager.currentDirectoryPath
但是路径总是有值。如何获取绝对路径,例如,如果从
/Users/xxx/sandbox/sample.app执行
.app
,我期望值
/Users/xxx/sandbox


可能吗?

使用
NSBundle

let path = NSBundle.mainBundle().bundleURL.URLByDeletingLastPathComponent!.path!