【问题标题】:Unresolvable error with Parse "Get Data In Background With Block"解析“使用块在后台获取数据”时出现无法解决的错误
【发布时间】:2015-04-12 21:54:20
【问题描述】:

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

swift:64:23: 无法调用“getDataInBackgroundWithBlock” '((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

【问题讨论】:

    标签: ios cocoa-touch swift parse-platform xcode6


    【解决方案1】:

    这是由于 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)
        }
    }
    

    【讨论】:

    • 做到了。非常感谢您的帮助!感谢您抽出宝贵时间。
    猜你喜欢
    • 2018-10-26
    • 1970-01-01
    • 2019-09-03
    • 2018-03-24
    • 2017-10-06
    • 2018-12-31
    • 1970-01-01
    • 2020-10-04
    • 2018-04-04
    相关资源
    最近更新 更多