IT *_*psy 7 ios parse-platform swift
我已经在GitHub,parse.com和其他地方检查了很多次语法,没有任何运气.问题是当我为PFObject调用saveInBackgroundWithBlock时,我收到以下错误:
无法使用类型'((Bool,NSError) - > Void)的参数列表调用'saveInBackgroundWithBlock'
我正在使用Xcode 6.3 beta 2.所有框架都加载到项目中(包括Bolts&Parse,但不是由parse.com ParseCrashReporting和ParseUI提供),<Parse/Parse.h>甚至<Bolts/Bolts.h>是通过Bridge Header引入的.
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)
}
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
该error参数应该是一个隐式解包的可选项,但不是success一个:
(success: Bool, error: NSError!) -> Void in
^ ^
Run Code Online (Sandbox Code Playgroud)
但是,除非您因任何原因需要指定类型,否则我建议您将闭包简单地用作:
(success, error) in
Run Code Online (Sandbox Code Playgroud)
不太容易出现类型声明错误.
在Swift 1.2中,.saveInBackgroundWithBlock的声明应如下所示:
Void saveInBackgroundWithBlock(block: PFBooleanResultBlock?(Bool, NSError?) -> Void)
Run Code Online (Sandbox Code Playgroud)
所以应该如下:
score.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
Run Code Online (Sandbox Code Playgroud)