So previously, in Swift 2.2 I could use Entity.image = UIImagePNGRepresentation(UIImage(named: "Image Name")!)
But now in Swift 3.0 it appears that we now have to use an extra step. Entity.image = NSData(data: UIImagePNGRepresentation(UIImage(named: "Image Name")!))
Or the object equivalent of UIImage(name: "Image Name")
Is there a new way in Swift 3.0 to go from UIImage
to NSData
?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
Try this:
if let img = UIImage(named: "hallo.png") {
let data = UIImagePNGRepresentation(img) as NSData?
}
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