Reputation: 477
I need to create an NSImage from a url. I want to be able to use it in my Mac application.
Please Help!!
Upvotes: 1
Views: 2923
Reputation: 477
Swift 5 and safely unwrap
do {
if let url = URL(string: imageURL) {
let imageData = try Data(contentsOf: url)
let image = NSImage(data: imageData)
}
} catch {
// Handle the error
}
Upvotes: 0
Reputation: 358
In Swift 4.2, we can already use:
let image: NSImage = NSImage(contentsOf: url!)!
Upvotes: 5