ios - 如何快速从解析中加载图像?

标签 ios swift parse-platform

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

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

    var userPhoto = PFObject(className: "postString")
    userPhoto["imageFile"] = imageFile
    userPhoto.saveInBackground()

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

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

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

最佳答案

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

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

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

关于ios - 如何快速从解析中加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24717302/

相关文章:

ios - 为什么来自 parse.com 的推送只能到达一台设备?

ios - 如何排除 "+"在 NSRegularExpression 中被视为特殊字符?

iphone - KVO vs NSNotification vs 协议(protocol)/代表?

ios - 导航栏的横向 View 问题

swift - Swift 中的 'open' 关键字是什么?

ios - 将文本字段输入表格时出现问题

ios - 使用缓存实现 PFQueryTableViewController

ios - 体系结构 x86_64 的 undefined symbol : "_OBJC_CLASS_$_CMMotionManager", 引用自 : objc-class-ref in GooglePlus(GPPSpamSignal. o)

ios - 单独的字符串 : 2 labels

ios - 使用 Parse (Swift 3) 注册用户时如何添加头像