简体   繁体   English

闭包快速调用Objective-C函数

[英]Calling Objective-C function in swift with a closure

I am using CRM Mobile SDK to access MS Dynamics CRM in iOS which is provided by Microsoft and that is in Objective-C. 我正在使用CRM Mobile SDK来访问Microsoft提供的,位于Objective-C中的iOS中的MS Dynamics CRM。 I want to use this sdk in Swift. 我想在Swift中使用这个SDK。 I use swiftify to convert sample Objective-C code into Swift but it is giving an error. 我使用swiftify将示例Objective-C代码转换为Swift,但出现错误。

Cannot invoke 'loginWithEndpoint' with an argument list of type '(String, completion: (ADAuthenticationResult) -> Void)' 无法使用类型为'(String,complete:(ADAuthenticationResult)-> Void)'的参数列表调用'loginWithEndpoint'

Function is called is 函数调用是

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

called like this 这样叫

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

According to sample function will be called in objective-c 根据样本函数将在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
    }
}];

There was an error in CRM SDK. CRM SDK中存在错误。 SDK is properly running in objective-c but not in swift and after updating xcode to 7.1.1 and swift 2.1 error changed. SDK可以在Objective-C中正常运行,但不能在Swift中正常运行,并且在将xcode更新为7.1.1和swift 2.1错误后,该软件无法正常运行。

Decided to use soap authentication instead as it is easy to use and don't need azure account to connect to crm 决定改用soap身份验证,因为它易于使用并且不需要azure帐户即可连接到crm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM