Parse 无法解决的错误 "Get Data In Background With Block"

Unresolvable error with Parse "Get Data In Background With Block"

我不知道这是用户错误还是由于 Xcode 和 Swift 更新。我正在从 Parse 中提取图像文件,无论我如何调整语法,我都会得到一个持续的错误:

swift:64:23: Cannot invoke 'getDataInBackgroundWithBlock' with an argument list of type '((NSData!, NSError?) -> Void)

我的代码是:

func callData() {

    var imageQuery = PFObject(className: "QuestionMaster")
    let iconImageFile = imageQuery["questionImage"] as! PFFile!
    iconImageFile.getDataInBackgroundWithBlock {
        (imageData: NSData!, error: NSError?) -> Void in

        if (error == nil) {

            self.icon1 = UIImage(data: imageData[0])
            self.icon2 = UIImage(data: imageData[1])
            self.icon3 = UIImage(data: imageData[2])
            self.icon4 = UIImage(data: imageData[3])
            self.icon5 = UIImage(data: imageData[4])
            self.icon6 = UIImage(data: imageData[5])
            self.icon7 = UIImage(data: imageData[6])
            self.icon8 = UIImage(data: imageData[7])
            self.icon9 = UIImage(data: imageData[8])
        }
        else {
            NSLog("Something went wrong.")
        }

我一直在直接从 Parse 文档开始工作。我也试过:

iconImageFile.getDataInBackgroundWithBlock(imageQuery, block: {
            (imageData: NSData!, error: NSError?) -> Void in

而且我交换了 !? 无济于事。 findObjectInBackgroundWithBlock.

我的代码中的其他地方也发生了同样的事情

这是由于 swift 1.2 中的更改所致。 Parse 应该已经提供了修复此问题的框架版本。从他们的网站下载。

编辑

此外,不要忘记用 if let

解包 imageData 值

以下代码适用于使用 swift 1.2

的最新 Parse 框架版本
imageFile.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

    if let imageData = imageData where error == nil
    {
        self.image = UIImage(data: imageData)
    }
}