在 macOS 应用程序中,我使用此代码在 Application Support 文件夹中创建一个目录。
let directoryURL = appSupportURL.appendingPathComponent("com.myCompany.myApp").appendingPathComponent("Documents")
如何在 Swift 中以编程方式获取字符串 com.myCompany.myApp?
我看到了这个问题,但我不确定如何在我的 macOS Swift 应用程序中使用它:Access App Identifier Prefix programmatically
最佳答案
if let bundleIdentifier = Bundle.main.bundleIdentifier {
appSupportURL.appendingPathComponent("\(bundleIdentifier)").appendingPathComponent("Documents")
}
一点解释:属性 bundleIdentifier 是可选的,因此您必须安全地解包该值,然后您就不会被要求输入任何感叹号 :)
关于swift - 如何在 Swift 中以编程方式获取应用程序 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44272374/