如何使用2个以上的参数在Swift中调用选择器

如何使用2个以上的参数在Swift中调用选择器,swift,nsdocument,Swift,Nsdocument,我正在覆盖Swift中的NSDocumentControllerreviewUnsavedDocuments(带AlertTitle:Cancelable:delegate:didReviewAllSelector:contextInfo:)。文档说明didReviewAllSelector具有此签名,请注意,它有3个参数: - (void)documentController:(NSDocumentController *)docController didReviewAll: (BOOL)

我正在覆盖Swift中的NSDocumentController
reviewUnsavedDocuments(带AlertTitle:Cancelable:delegate:didReviewAllSelector:contextInfo:)
。文档说明didReviewAllSelector具有此签名,请注意,它有3个参数:

- (void)documentController:(NSDocumentController *)docController  didReviewAll: (BOOL)didReviewAll contextInfo:(void *)contextInfo
因此,我需要使用三个参数调用
委托
上的
选择器
。我面临的问题是,我似乎找不到一个简洁的方法来用swift实现这一点

我能找到的最接近的匹配是NSObject已经执行了两个参数。有没有这样的3个参数

Examaple代码

func reviewUnsavedDocuments(withAlertTitle title: String?, cancellable: Bool, delegate: Any?, didReviewAllSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {

  if let object = delegate as? NSObject {
    object.perform(didReviewAllSelector, with: self, with: true ... and
              now I need to add contextInfo as a third paramenter here?
  }
}
我已经使用NSInvocation在obj-c中成功地完成了这项工作。但swift不提供此功能:(

使用
@convention(c)
自swift 3起提供

let methodIMP: IMP! = object.method(for: didReviewAllSelector)
unsafeBitCast(methodIMP,to:(@convention(c)(Any?,Selector,Any?,Bool, OpaquePointer)->Void).self)(object,didReviewAllSelector,self,true,OpaquePointer(contextInfo)) 
我的回答中包含了更多信息和示例

我相信,
OpaquePointer
应该适用于您的第三个arg,但如果您遇到任何问题,请告诉我。

使用自Swift 3起提供的
@convention(c)

let methodIMP: IMP! = object.method(for: didReviewAllSelector)
unsafeBitCast(methodIMP,to:(@convention(c)(Any?,Selector,Any?,Bool, OpaquePointer)->Void).self)(object,didReviewAllSelector,self,true,OpaquePointer(contextInfo)) 
我的回答中包含了更多信息和示例


我相信,
OpaquePointer
应该适用于您的第三个参数,但如果您遇到任何问题,请告诉我。

我无法控制
delegate
selector
。它是从一个框架传递给我的。这是我在NSDocumentController上重写的一个系统方法。我最终编写了一个使用NSInvocation的obj-c类。I无法控制
委托
选择器
。它是从框架传递给我的。这是我在NSDocumentController上重写的系统方法。我最终编写了一个使用NSInvocation的obj-c类。