如何从swift中parsing图像?

我想知道是否有人可以帮助我,我是新的应用程序开发我从我的应用程序上传图像parsing文件的帮助没有问题。

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) } } 

“另一个照片”从哪里来? parsing没有说“在这里我们检索另一个名为anotherPhoto UserPhoto的图像文件:”

anotherPhoto将是您的postString (上传示例中的postString一个实例。 为你工作的文件下载例子是这样的:

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

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