无法将类型 'Data?' 的值转换为预期的参数类型“UIImage”
Cannot convert value of type 'Data?' to expected argument type 'UIImage
我正在尝试获取图像数据,但出现此错误:
Cannot convert value of type 'Data?' to expected argument type 'UIImage'
代码:
if let image = profileImageView.image {
if let imageData = UIImagePNGRepresentation(image.pngData()) {
PFUser.current()?["photo"] = PFFileObject(name: "profile.png", data: imageData)
}
}
我哪里做错了?
UIImagePNGRepresentation
的初始值设定项采用 UIImage
实例而不是 Data
实例,因此替换
if let imageData = UIImagePNGRepresentation(image.pngData()) {
和
if let imageData = UIImagePNGRepresentation(image) {
或者最好使用最新的 Way
if let imageData = image.pngData() {
我正在尝试获取图像数据,但出现此错误:
Cannot convert value of type 'Data?' to expected argument type 'UIImage'
代码:
if let image = profileImageView.image {
if let imageData = UIImagePNGRepresentation(image.pngData()) {
PFUser.current()?["photo"] = PFFileObject(name: "profile.png", data: imageData)
}
}
我哪里做错了?
UIImagePNGRepresentation
的初始值设定项采用 UIImage
实例而不是 Data
实例,因此替换
if let imageData = UIImagePNGRepresentation(image.pngData()) {
和
if let imageData = UIImagePNGRepresentation(image) {
或者最好使用最新的 Way
if let imageData = image.pngData() {