Getting and Comparing Type of Class
class BaseClass: NSObject { | |
func test() { | |
let aType = type(of: self) | |
if aType == dict["My Base"] { | |
print("this is base") | |
} else if aType == dict["My Inherited"] { | |
print("this is inherited") | |
} | |
print(aType) | |
} | |
} | |
class InheritedClass: BaseClass { | |
override func test() { | |
print("from inherited...") | |
super.test() | |
} | |
} | |
let dict = [ | |
"My Base": BaseClass.self, | |
"My Inherited": InheritedClass.self, | |
] | |
BaseClass().test() | |
InheritedClass().test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Output:
this is base
BaseClass
from inherited...
this is inherited
InheritedClass