我有解析和swift的问题,我希望你能帮助我:)
我正在从Parse下载字符串和PFfiles,并希望将其添加到数组中(这很好).
然后我想用字符串数组填充Label(也可以正常工作)和带有PFFile数组的UIImageView,它也是一个Image.
但我总是得到一个错误:
PFFile is not convertible to “UIImage
但是我不知道如何转换这个PFFile以便我可以将它与UIImage View一起使用.
var titles = [String] () var fragenImages = [PFFile] () @IBOutlet weak var fragenIm: UIImageView! @IBOutlet weak var fragenFeld: UILabel! override func viewDidAppear(animated: Bool) { var query = PFQuery(className:"Post") query.whereKey("user",notEqualTo: PFUser.currentUser().username) query.limit = 5 query.findObjectsInBackgroundWithBlock{ (objects: [AnyObject]!,error: NSError!) -> Void in if error == nil { for object in objects { self.titles.append(object["title"] as String) self.fragenImages.append(object["imageFile"] as PFFile) } self.fragenFeld.text = self.titles[0] self.fragenIm.image = self.fragenImages[0] } else { println(error) } } }
丹尼尔,图片不是文件,从技术上讲它们是,但你将它们称为数据而不是PFObjects或PFFiles.因此,基本上获取文件的数据并按照通常的方式应用:您只是错过了一个简单的步骤:
for object in objects { let userPicture = object["imageFile"] as PFFile userPicture.getDataInBackgroundWithBlock({ // This is the part your overlooking (imageData: NSData!,error: NSError!) -> Void in if (error == nil) { let image = UIImage(data:imageData) self.fragenImages.append(image) })