我尝试将 Objective-C 块语法转换为 Swift Xcode 6.3.2
完成块类型定义:
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)")
}
})
但它告诉我错误
预期的 ',' 分隔符
表达式列表中的预期表达式