如何将 Objective-C 的完成块转换为 Swift?
How to convert completion block of Objective-C to Swift?
我尝试将 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)")
}
})
但它显示错误
Expected ',' separator
Expected expression in list of expressions
你试过了吗
Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
if success {
println("inserted")
} else {
println("Not inserted \(responseError.description)")
}
})
我尝试将 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)")
}
})
但它显示错误
Expected ',' separator
Expected expression in list of expressions
你试过了吗
Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
if success {
println("inserted")
} else {
println("Not inserted \(responseError.description)")
}
})