I've been trying to save the output of a macOS app to my desktop. This is the code I'm using to do so:
let homePath = FileManager.default.homeDirectoryForCurrentUser let desktopPath = homePath.appendingPathComponent("Desktop") print(desktopPath) let filePath = desktopPath.appendingPathComponent("TestFile.txt") do { try unicodeString.write(to: filePath, atomically: false, encoding: .utf8) } catch { errorMessage = error.localizedDescription + "\n" + unicodeString }
And this is the error I get:
You don’t have permission to save the file “TestFile.txt” in the folder “Desktop”.
The path that's printed looks like this:
file:///Users/DKJ/Library/Containers/com.hatzicware.FileCreator/Data/Desktop
which of course is not on my desktop. How do I construct a path that will let me save the file?
I get the same error running the app both in Xcode, and on its own in Finder.