I don't understand why for creating UIImage
I just pass String
in constructor but for creating NSImage
I have to pass NSImage.Name
in constructor. What idea is laying behind this solution?
Code:
iOS
let image = UIImage(named: "name")
Mac OS
let image = NSImage(named: NSImage.Name("name"))
Thanks.
The expectation is that you have a centralized spot where you extend NSImage.Name
with static constants that define all your image names. Then, all your code references these single members, rather than repeating magic strings.
extension NSImage.Name {
static let square = NSImage.Name("square")
static let triangle = NSImage.Name("triangle")
static let circle = NSImage.Name("circle")
}
//...
let image = NSImage(named: .square)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With