I have this simply code, that I run with Catalyst in macOS:
struct ContentView: View {
@State private var pathURL = "/Users/cesare/Desktop/Test"
var body: some View {
VStack {
TextField("/Users/cesare/Desktop/Test", text: $pathURL)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Button(action: {
let fileUrl = URL(fileURLWithPath: self.pathURL, isDirectory: true)
let nameImage = "ImageTest" + ".jpg"
let fileUrlWithName = fileUrl.appendingPathComponent(nameImage)
let imageData = UIImage(named: "2020-03-05_11-19-22_5")?.jpegData(compressionQuality: 1)
do {
try imageData!.write(to: fileUrlWithName)
} catch {
print("** saveImageData error: \(error.localizedDescription)")
}
}) {
Text("Save Image")
}
}
}
}
In Assets.xcassets
I put 2020-03-05_11-19-22_5
image. When I press Save Image
button, I have this error: You don’t have permission to save the file “ImageTest.jpg” in the folder “Test”.
Why I don't have permission for save image in my Desktop?
I tried to export the app contained in Products, without getting any results.
Which path should I use to save an image in my Mac local disk?