Unresolvable error with Parse “Get Data In Background With Block”

不羁岁月 提交于 2019-12-11 13:07:18

问题


I don't know if this is user error or due to the Xcode and Swift updates. I'm pulling image files off of Parse and no matter how I tweak the syntax I get a persistent error of:

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

My code is:

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

I've been working straight from the Parse docs. I have also tried:

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

And I've exchanged ! and ? to no avail. The same things happens elsewhere in my code with findObjectInBackgroundWithBlock.


回答1:


This is due the changes in swift 1.2. Parse should have already provided a version of their framework that fixes this. Download it from their website.

Edit

Also, don't forget to unwrap the imageData value with if let

The following code works for me on the lastest Parse framework version using swift 1.2

imageFile.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

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


来源:https://stackoverflow.com/questions/29595084/unresolvable-error-with-parse-get-data-in-background-with-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!