I try to convert Objective-C block syntax to Swift Xcode 6.3.2
completion block 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);
}
}];
After surfing on net, I tried with
Model.insertObjectWithTable("tblStudent", values: dict, completion:({(success:Bool,responseError:NSError, object:NSString)->(Void) in
if success
{
println("inserted")
}
else
{
println("Not inserted \(responseError.description)")
}
})
}
and
Model.insertObjectWithTable("tblStudent", values: dict, completion:(success:Bool,responseError:NSError, object:NSString)->Void{
if success
{
println("inserted")
}
else
{
println("Not inserted \(responseError.description)")
}
})
but it shows me error
Expected ',' separator
Expected expression in list of expressions
Have you tried
Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
if success {
println("inserted")
} else {
println("Not inserted \(responseError.description)")
}
})