我尝试将Objective-C块语法转换为Swift Xcode 6.3.2
完成块typedef:
typealias CompletionWithBoolBlock = (Bool, NSError, NSString) -> Void
[Model insertObjectWithTable:@"tblStudent" values:dict completion:^(BOOL success, NSError *responseError, NSString *object){
if(success){
NSLog(@"inserted");
}
else
{
NSLog(@"Not inserted, %@",responseError.description);
}
}];
在网上冲浪后,我尝试了
Model.insertObjectWithTable("tblStudent", values: dict, completion:({(success:Bool,responseError:NSError, object:NSString)->(Void) in
if success
{
println("inserted")
}
else
{
println("Not inserted \(responseError.description)")
}
})
}
和
Model.insertObjectWithTable("tblStudent", values: dict, completion:(success:Bool,responseError:NSError, object:NSString)->Void{
if success
{
println("inserted")
}
else
{
println("Not inserted \(responseError.description)")
}
})
但它显示我错误
预期的','分隔符
表达式列表中的期望表达式
你有没有尝试过
Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
if success {
println("inserted")
} else {
println("Not inserted \(responseError.description)")
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句