问题
I am trying to use the pngData() instance method of the UIImage class of Apple's UIKit Framework according to this documentation:
https://developer.apple.com/documentation/uikit/uiimage/1624096-pngdata
When I type the method in Xcode, I get an error saying:
Value of type 'UIImage?' has no member 'pngData'
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let image = UIImage(named: "moroni.png")
let dataImage = image.pngData() // Value of type 'UIImage?' has no member 'pngData'
}
回答1:
Well, I don't know why the Document's page display wrong, but your function
image.pngData()
can only use from Swift 4.2 (and later, maybe), but your Xcode 9.4.1 only supports to Swift 4.1.
From the older Swift version, you can (only) using
UIImagePNGRepresentation(_ image: UIImage) -> Data?
来源:https://stackoverflow.com/questions/51336592/why-will-xcode-9-4-1-not-allow-me-to-use-the-uiimage-pngdata-instance-method