我正在尝试但无法确定是否有办法使用swift来检测正在运行的.app文件的路径和名称
即如果我的应用程序是selfupdater.app并且它存储在~username / applications
中如何在swift
中将selfupdater.app作为字符串变量启动时获取此信息答案 0 :(得分:0)
这称为主捆绑文件夹。
Swift 3或更高版本
extension URL {
var parentDirectory: URL? {
return (try? resourceValues(forKeys: [.parentDirectoryURLKey]))?.parentDirectory
}
}
let bundleURL = Bundle.main.bundleURL
if let path = bundleURL.parentDirectory?.path {
print(path)
}