无法将objc块转换为swift

时间:2015-09-28 13:16:08

标签: objective-c swift quickblox

将此代码转换为swift时,我收到错误,但我无法执行此操作。 请帮我把这段objc代码转换成swift。

[QBRequest createSessionWithSuccessBlock:^(QBResponse *response, QBASession *session) {
    // session created

    QBUUser *user = [QBUUser user];
    user.password = @"azhhdsf";
    user.login = @"dsfgsgf";

    // Registration/sign up of User
    [QBRequest signUp:user successBlock:^(QBResponse *response, QBUUser *user) {
        // Sign up was successful
    } errorBlock:^(QBResponse *response) {
        // Handle error here
        NSLog(@"error while signing up with QB");
    }];
} errorBlock:^(QBResponse *response) {
    // handle errors
    NSLog(@"%@", response.error);
}];

在swift中,我所做的是:

QBRequest.createSessionWithSuccessBlock({response: QBResponse!,session: QBASession! in
            let user = QBUUser()
            user.ID = 125345
            user.password = "kjjhfdsf"

            QBRequest.signUp(user, successBlock: nil, errorBlock: nil)
            }, errorBlock: {(response: QBResponse!) in
                println("error")
        })
抱歉这个愚蠢的问题,但我无法执行。

1 个答案:

答案 0 :(得分:1)

看起来像这样:

QBRequest.createSessionWithSuccessBlock({ (response: QBResponse, session: QBASession) in
    let user = QBUUser()
    user.password = "azhhdsf"
    user.login = "dsfgsgf"
    QBRequest.signUp(user, successBlock: {(response: QBResponse, user: QBUUser) in
            // Sign up was successful
        }, errorBlock: {(response: QBResponse) in
            // Handle error here
            NSLog("error while signing up with QB")
    })}, errorBlock: {(response: QBResponse) in
        // handle errors
        NSLog("%@", response.error)
    }
)