Obj-C to Swift3 for class returning method

Tien Nguyen

So I have this method in Obj-C superclass:

+ (Class<Executor>)executorClass

I need to override it in my Swift3 child class. What I tried:

override class func executorClass() -> AnyClass // not match

override class func executorClass() -> Executor.Type // not match

override class func executorClass() -> AnyObject.Type // not match

override class func executorClass() -> Any.Type // obviously not match

Before in Swift2 the following code worked:

override class func executorClass() -> AnyObject.Type
Tien Nguyen

Credit to @Harnish

The Class<Executor> in Obj-C method isn't legal, but still compilable. Removing <Executor> solves compilation. aka:

// Obj-C
+ (Class)executorClass

// Swift
override class func executorClass() -> AnyClass  // good

Edit: credit to @Sulthan

+ (Class<Executor>)executorClass

Above code is fully legal if Executor was protocol. However in my case it was another class. So, I guessing, this was the root of the problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related