I am trying to save images on a macOS Catalyst app using the below code. It was adopted from SwiftUI Catalyst App in macOS computer - Which path should I use to save an image in my Mac local disk?
However I get the error "The file "abstract-1.jpg" doesn't exist."
I have the image abstract-1 in my Assets.xcassets folder, so I'm not sure why it's not seeing it for this save operation? I've also tried just using item.name
without appending the .jpg but it produces the same error. Any ideas? Thanks!
Button(action: {
let fileURL = URL(fileURLWithPath: self.pathURL, isDirectory: true)
let nameImage = item.name + ".jpg"
let fileURLwithName = fileURL.appendingPathComponent(nameImage)
let imageData = UIImage(named: item.name)?.jpegData(compressionQuality: 1)
do {
try imageData!.write(to: fileURLwithName)
} catch {
print("** saveImageData error: \(error.localizedDescription)")
}
}) {
Label("Save to Pictures Directory", systemImage: "square.and.arrow.down")
}