我很难在macos上的用户下载目录中使用以下代码创建一个文件夹:
static func createFolderInDownloadsDirectory() {
let downloadsDirectory = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!
let downloadsDirectoryWithFolder = downloadsDirectory.appendingPathComponent("FolderToCreate")
do {
try FileManager.default.createDirectory(at: downloadsDirectoryWithFolder, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
}
这是输出:
You don’t have permission to save the file “FolderToCreate” in the folder “Downloads”.
我该如何解决这个问题?