Reputation: 321
How can I check if a class is a subclass of another class using types only, without objects?
Something like:
class SuperClass {}
class SubClass: SuperClass {}
SuperClass.self == SubClass.self // should return true, but it returns false
Upvotes: 1
Views: 724
Reputation: 119128
Your classes should inherit from the NSObject
. Then you can check that like:
import Foundation
class SuperClass: NSObject { }
class SubClass: SuperClass { }
SubClass.isSubclass(of: SuperClass.self) // Returns true
Upvotes: 2