检测您的可可快速应用程序正在运行的位置 [英] Detecting the Location your cocoa swift application is running from
本文介绍了检测您的可可快速应用程序正在运行的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试但无法找出是否有一种方法可以使用swift检测正在运行的.app文件的路径和名称
I'm trying but unable to find out if there is a way using swift to detect the path and name of the .app file that is running
ie if我的应用程序是selfupdater.app,它存储在〜username / applications中
ie if my app is selfupdater.app and its stored in ~username/applications
当selfupdater.app作为swift中的字符串变量启动时,如何获取此信息
how can i get this information when selfupdater.app is launched as a string variable in swift
推荐答案
这称为您的主捆绑包文件夹。
This is called your main bundle folder.
迅速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)
}
这篇关于检测您的可可快速应用程序正在运行的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文