如何在swift中加载解析图像?

Tim*_*Tim 5 ios parse-platform swift

我想知道是否有人可以帮助我,我是应用程序开发的新手我正在从我的应用程序上传图像解析,解析文档的帮助没有问题.

    let imageData = UIImagePNGRepresentation(scaledImage)
    let imageFile: PFFile = PFFile(data: imageData)

    var userPhoto = PFObject(className: "postString")
    userPhoto["imageFile"] = imageFile
    userPhoto.saveInBackground()
Run Code Online (Sandbox Code Playgroud)

但是当我添加代码来检索图像时,我有点迷失:/

let userImageFile = anotherPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
  if !error {
     let image = UIImage(data:imageData)
   }
}
Run Code Online (Sandbox Code Playgroud)

"anotherPhoto"来自哪里?Parse确实说过"我们在这里从另一个名为anotherPhoto的UserPhoto中检索图像文件:"

Nic*_*ick 5

anotherPhoto将是您的postString(userPhoto在您的上传示例中) 的一个实例。适合您的文件下载示例如下:

let userImageFile = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
    (imageData: NSData!, error: NSError!) -> Void in
    if !error {
        let image = UIImage(data:imageData)
    }
}
Run Code Online (Sandbox Code Playgroud)

任何 PFFile 都必须从普通的 PFObject 引用,否则无法检索。PFFile 对象本身不会显示在数据浏览器中。