Getting "Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file" unexpectedly while attempting to create a small log file. Here's some background.
This is a Swift app I wrote for my own use six years ago.
A week ago, I made a small update to the app, which has not been changed in over two years. First time using Xcode 16.4 on this app, which required some code updates of course. The code creating this file has not been changed.
Now for the first time, I'm getting this permissions error on a folder with wide-open permissions.
This is the code. Worked for years under previous versions of Xcode.
*
if let outputURL = URL(string: "file://" + logPath + "/output_" + outputFormatter.string(from:Date()) + ".txt"){
do{
try outputString.write(to: outputURL, atomically:false, encoding: .utf8)
}catch let error as NSError{
print ("log write error (error) (nl) (outputString)")
}
}
Mac Permissions Issue - Likely involving Xcode
What is "logPath"? It sounds like you may have sandboxed the app. It probably no longer has access to whatever logPath is. Since this is your own app, the easiest solution would be to disable the sandbox. If you want to be clever, you could give yourself a temporary exception entitlement for that path.