我已经在 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/