【问题标题】:Mapping an Objective-C selector to Swift将 Objective-C 选择器映射到 Swift
【发布时间】:2015-07-13 13:46:35
【问题描述】:

我正在使用适用于 IOS 的 Google Calendar API。我已经桥接了它,以便我可以快速使用它。在调用回调之前,授权一直有效(即我可以在我的 Google 帐户中看到授权已发生)。

their example 中,他们有一个选择器来处理成功的身份验证,如下所示。

// Handle completion of the authorization process, and update the Google Calendar API
// with the new credentials.
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuth2Authentication *)authResult
                 error:(NSError *)error {
    //...
}

我已将这个选择器翻译如下...

func finishedAuthorisation(viewController:GTMOAuth2ViewControllerTouch?, authResult:GTMOAuth2Authentication?, error:NSError?){
    //...
}

...并像这样使用它...

GTMOAuth2ViewControllerTouch(scope: " ".join(scopes), clientID: kClientID, clientSecret: kClientSecret, keychainItemName: kKeychainItemName, delegate: self, finishedSelector: "finishedAuthorisation:")

...导致此错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation _invocationWithMethodSignature:frame:]: method signature argument cannot be nil'

我在这里做错了什么?

【问题讨论】:

标签: ios objective-c iphone swift ipad


【解决方案1】:

我通过使用这个选择器finishedAuthorisation:authResult:error:解决了它

在实践中:

处理方法:

func finishedAuthorisation(viewController:GTMOAuth2ViewControllerTouch, authResult:GTMOAuth2Authentication, error:NSError?) {
    ...
}

以及我是如何使用选择器的:

GTMOAuth2ViewControllerTouch(scope: " ".join(scopes), clientID: kClientID, clientSecret: kClientSecret, keychainItemName: kKeychainItemName, delegate: self, finishedSelector: "finishedAuthorisation:authResult:error:")

【讨论】:

    【解决方案2】:

    您的 finishedAuthorisation 选择器采用三个参数。尝试输入三个冒号:“finishedAuthorisation:::”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-13
      • 2014-05-16
      • 2011-11-07
      • 2016-12-14
      • 2011-06-27
      • 2011-08-09
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多