1

我尝试将 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)")
            }
        })

但它告诉我错误

预期的 ',' 分隔符

表达式列表中的预期表达式

4

1 回答 1

2

你有没有尝试过

Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
    if success {
        println("inserted")
    } else {
        println("Not inserted \(responseError.description)")
    }
})
于 2015-06-06T19:58:58.090 回答