gpt4 book ai didi

swift - 通过 getDataInBackgroundWithBlock 检索 PFFile 时出错

转载 作者:可可西里 更新时间:2023-11-01 02:21:29 26 4
gpt4 key购买 nike

我创建了一个 var userImages = [PFFile]() 并通过用户查询和 self.userImages.append(user["imageFile"] 作为 !PFFile)。这很好用。但是,当我尝试通过

设置用户图像时

userImages.getDataInBackGroundWithBlock{ (data, error) -> Void in ...

我收到以下错误:**“[(PFFile)]”没有名为“getDataInBackGroundWithBlock”的成员**

为什么这行不通,什么可能是这个问题的解决方案?

谢谢你的帮助!!

enter image description here

enter image description here

最佳答案

您正在尝试在数组中调用 getDataInBackGroundWithBlock 尝试使用"

userImages.last?.getDataInBackGroundWithBlock{...}

或者您可以将它保存在一个变量中并使用新的 PFFIle 来检索图像

let userImage = user["imageFile"] as! PFFile
userImage.getDataInBackGroundWithBlock{...}

或直接使用:

(user["imageFile"] as! PFFile).getDataInBackGroundWithBlock{...}

角色过程是:

self.userImages.append(user["imageFile"] as! PFFile) //This is just a reference to download the image

userImages.last?.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData) // this is the final image
}
}
}

关于swift - 通过 getDataInBackgroundWithBlock 检索 PFFile 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30701825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com