我开始使用 swift 编程大约两周了,我仍然想在我的应用程序中使用一些 Objective C 类。一个例子是从 Swift 调用此方法:
+ (void)transitionFromThisVCClass:(Class<SomeProtocol>)aFromVCClass
ToThisClassVCClass:(Class<SomeProtocol>)aToVCClass
WithNavigationController:(UINavigationController *)aNav
WithDuration:(NSTimeInterval)aDuration
我的问题是我找不到像在 Objective C [SomeClass class] 中那样传递类类型的方法。任何对此的帮助将不胜感激。谢谢
更新
如果我尝试像这样使用 MyClass.self:
ASFSharedViewTransition.addTransitionWithFromViewControllerClass(
RecommendationListViewController.self,
toViewControllerClass: RecommendationViewController.self,
withNavigationController: self.window?.rootViewController,
withDuration: 0.3)
ASFSharedViewTransition 是一个 objective-c 类,我尝试从 swift 调用它
我收到此错误:
Cannot convert the expression's type '(RecommendationListViewController.Type,
toViewControllerClass: RecommendationViewController.Type,
withNavigationController: $T5??,
withDuration: FloatLiteralConvertible)'
to type 'FloatLiteralConvertible'
最佳答案
您可以使用foo.self
,其中foo
是类名。例如,MyClass.self
关于objective-c - 如何在 Swift 中调用需要运行时类作为参数的 Objective C 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26697352/