- Independent Apple developer.
- Mac app evangelist.
- Swift & Swift UI enthusiast.
- Author of macOS Apprentice
- Author of macOS by Tutorials
Read my blog posts at https://troz.net
Follow me on Mastodon, other links at Linktree
Sample app to accompany article.
Read my blog posts at https://troz.net
Follow me on Mastodon, other links at Linktree
I have read with great interest yours: SwiftUI for Mac
.
I would like to know how to save an image on the local disk by providing a URL, for example from CoreData or more simply as in my little app:
struct ContentView: View {
var body: some View {
Button(action: {
let fileUrl = URL(fileURLWithPath: "/Users/cesare/Desktop/Test", 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")
}
}
}
which does not work, giving the following error: You don’t have permission to save the file “ImageTest.jpg” in the folder “Test”.
How should I modify the code to avoid this error which, as you wrote, it was another macOS Catalina security issue
?
Obviously I configured the app as you wrote very well, without getting the desired result.
I thank you in advance for the help you can give me.
EmbeddedColorWell.txt
Thanks for the articles and code examples! It has helped me immensely.
I noticed that the selectedColor in the EmbeddedColorWell is not being mutated and is not being used in a two-way manner. The selectedColor is initialized to NSColor.blue and used to set the color in the NSColorWell view. When the NSColorWell color is changed, it does change the color of the EmbeddedColorWell view. However, the actual @State var selectedColor value is never mutated in this process beyond the initialized value of NSColor.blue.
To see this, add the .background modifier to the Text as shown below:
HStack { Text("Choose a color:") .background(Color(selectedColor)) EmbeddedColorWell(selectedColor: $selectedColor) .frame(width: 44, height: 23) }
When the color is chosen in the NSColorWell, the background color does not change.
Attached is a modified version of the EmbeddedColorWell that will alter the value of selectedColor when the NSColorWell.color changes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.