将Objective-C块转换为Swift 2.0

时间:2016-01-28 12:21:38

标签: swift closures objective-c-blocks

Objective-C块:

[networHandler composeRequestWithMethod:MethodRespondToAppointMent
                                        paramas:queryParams        //NSDictionary
                                   onComplition:^(BOOL success, NSDictionary *response){
    //                                   NSLog(@"Dict: %@", response);
    }];

现在我想在Swift中代表这一点。我该怎么办?

更新

let handler = NetworkHandler.sharedInstance() as! NetworkHandler
        let dict = ["":""]

        handler.composeRequestWithMethod("", paramas: dict) { (success, response) -> Void in

        }

这对我有用。

1 个答案:

答案 0 :(得分:0)

在Swift中,如果尾随参数是一个闭包,你也可以使用缩短版的Anbu.Karthik的答案:

networHandler.composeRequestWithMethod(MethodRespondToAppointMent, paramas: queryParams) { success, response in
//      NSLog(@"Dict: %@", response)
}