【发布时间】:2021-03-23 22:59:22
【问题描述】:
我有一个适用于 MacOS 的 swift 代码,我正在尝试将一个简单的文件写入桌面:
let header="Hello world"
let desktopPath = FileManager.default.urls(for: .desktopDirectory, in: .userDomainMask)
let FbxFile = desktopPath[0].appendingPathComponent("output.fbx")
NSLog(FbxFile.absoluteString) // --> Proper path to desktop
do {
try header.write(to: FbxFile, atomically: false, encoding: .utf8)
}
catch { NSLog("Error writing") }
但是,我在写作时总是出错。
在我的 info.plist 中,我添加了一个 NSDesktopFolderUsageDescription 键(隐私 - 桌面文件夹使用说明),但从未收到提示。
我错过了什么?
【问题讨论】: