用闭包调用swift中的Objective-C函数



我正在使用CRM Mobile SDK访问iOS中的MS Dynamics CRM,该软件由Microsoft提供,位于Objective-C中。我想在Swift中使用这个sdk。我使用swiftify将示例Objective-C代码转换为Swift,但它给出了一个错误。

无法使用类型的参数列表调用"loginWithEndpoint"(字符串,完成:(ADAuthenticationResult)->Void)

函数被调用为

- (void)loginWithEndpoint:(NSString *)serverURL completion:(ADAuthenticationCallback)completion;

像这样叫

CRMClient.sharedClient().loginWithEndpoint(host, completion: {(result: ADAuthenticationResult) -> Void in
            if result.error {
                // TODO: Handle the error
            }
            else {
                // TODO: Do some work
            }
        })

根据示例函数将在objective-c 中调用

    CRMClient *client = [CRMClient sharedClient];
[client loginWithEndpoint:@"https://mydomain.crm.dynamics.com" completion:^(ADAuthenticationResult *result) {
    if (result.error) {
        // TODO: Handle the error
    }
    else {
        // TODO: Do some work
    }
}];

CRM SDK中存在错误。SDK在objective-c中正常运行,但在swift中没有,并且在将xcode更新为7.1.1后,swift 2.1错误发生了更改。

决定使用soap身份验证,因为它很容易使用,不需要azure帐户即可连接到crm

最新更新