ios - 无法调用 'saveInBackgroundWithBlock'

标签 ios parse-platform swift

我已经在 GitHub、parse.com 和其他地方检查了语法无数次,但没有任何运气。问题是当我为 PFObject 调用 saveInBackgroundWithBlock 时出现以下错误:

Cannot invoke 'saveInBackgroundWithBlock' with an argument list of type '((Bool, NSError) -> Void)'

我在 Xcode 6.3 beta 2 上。所有框架都加载到项目中(包括 Bolts 和 Parse,但 parse.com ParseCrashReporting 和 ParseUI 不提供),<Parse/Parse.h>甚至 <Bolts/Bolts.h>是通过桥头带来的。

var score = PFObject(className: "score")
    score.setObject("Rob", forKey: "name")
    score.setObject(95, forKey: "scoreNumber")
    score.saveInBackgroundWithBlock {
        (success: Bool!, error: NSError) -> Void in
        if success == true {
            println("Score created with ID: \(score.objectId)")
        } else {
            println(error)
        }
    }

有什么想法吗?

最佳答案

error 参数应该是一个隐式展开的可选参数,但不是 success 参数:

(success: Bool, error: NSError!) -> Void in
              ^               ^

然而,除非你出于某种原因需要指定类型,否则我建议你简单地使用闭包:

(success, error) in

不太容易出现类型声明错误。

关于ios - 无法调用 'saveInBackgroundWithBlock',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889289/

相关文章:

ios - 检测何时 requestAlwaysAuthorization 未调用 iOS 14

ios - swift 3 错误 : "Binary operator ' /' cannot be applied to two ' int' operands"

swift - 如何将字符串转换为utf-8? ( swift ,Alamofire)

iphone - iOS 音乐播放器的公共(public) API?

iphone - AVAssetImageGenerator 提供旋转的图像

ios - 将 PFQuery 解析为数组 objective-c

javascript - 将图像上传到parse.com并保存到数据库中

ios - Objective-C Self 和 Synthesize 关键字

ios - mapKeyPath 问题

ios - 将字符串查询解析为数组