alex
alex

Reputation: 957

How to call an Objective C method in Swift that requires a runtime class as a parameter

I started programming in swift for about 2 weeks now and I still have some Objective C classes I would like to use in my app. One example would be calling this method from Swift:

+ (void)transitionFromThisVCClass:(Class<SomeProtocol>)aFromVCClass
                       ToThisClassVCClass:(Class<SomeProtocol>)aToVCClass
                    WithNavigationController:(UINavigationController *)aNav
                                WithDuration:(NSTimeInterval)aDuration

My problem is that I can't find a way to pass in a class type like I would have done in Objective C [SomeClass class]. Any help with this would be much appreciated. Thanks

UPDATE

If I'm trying to use MyClass.self like so:

ASFSharedViewTransition.addTransitionWithFromViewControllerClass(
     RecommendationListViewController.self,
     toViewControllerClass: RecommendationViewController.self,
     withNavigationController: self.window?.rootViewController,
     withDuration: 0.3)

ASFSharedViewTransition is an objective c class that I'm trying to call from swift

I get this error:

Cannot convert the expression's type '(RecommendationListViewController.Type,
toViewControllerClass: RecommendationViewController.Type,
withNavigationController: $T5??,
withDuration: FloatLiteralConvertible)'
to type 'FloatLiteralConvertible'

Upvotes: 0

Views: 149

Answers (1)

DPlusV
DPlusV

Reputation: 14336

You can use foo.self, where foo is the class name. For example, MyClass.self

Upvotes: 1

Related Questions