我有一个混合的Swift和Objective C应用程序.swift应用程序使用一些ObjectiveC库来处理OAuth2身份验证.其中一部分是对令牌的OAuth2请求完成后对委托方法的回调.
以下代码正在Objective C库(GTMOAuth2)中执行,该库使用我传入的选择器:
if (delegate_ && finishedSelector_) {
SEL sel = finishedSelector_;
NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
[invocation setSelector:sel];
[invocation setTarget:delegate_];
[invocation setArgument:&self atIndex:2];
[invocation setArgument:&auth atIndex:3];
[invocation setArgument:&error atIndex:4];
[invocation invoke];
}
Run Code Online (Sandbox Code Playgroud)
我想要调用的函数是在我的swift viewController中,看起来像这样:
func authentication(viewController: GTMOAuth2ViewControllerTouch, finishedWithAuth: GTMOAuth2Authentication, error: NSError)
{
if (error != nil)
{
var alertView: UIAlertView = UIAlertView(title: "Authorisation Failed", message: error.description, delegate: self, cancelButtonTitle: "Dismiss")
alertView.show()
}
else
{
// Authentication Succeeded
self.mytoken = finishedWithAuth.accessToken
}
}
Run Code Online (Sandbox Code Playgroud)
我目前传入的选择器是: …