Why will Xcode 9.4.1 not allow me to use the UIImage pngData() instance method?

本秂侑毒 提交于 2020-06-13 07:56:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!