Swift:imageWithData不可用

Nic*_*ick 1 xcode uiimage ios swift

我通过将图像数据传递给它来在swift中创建一个UIImage对象.类似于它在objective-c中的完成方式

UIImage imageWithData
Run Code Online (Sandbox Code Playgroud)

但是,我看到错误说:imageWithData不适用于swift.

对于Swift的imageWithData有什么替代方案?

Lor*_*olt 8

imageWithData在UIImage文档中找不到类方法,但是你可以使用init(data:)数据方法:

let image:UIImage = UIImage(data:youDataHere);
Run Code Online (Sandbox Code Playgroud)