使用swift获取OS X中.app捆绑包的绝对路径
我试图找到一个简单的OSX应用程序运行的路径。我试过了使用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
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!