To instantiate a Swift class dynamically using NSClassFromSwift. This works for ObjC as well as pure Swift classes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourClass { | |
required init() { | |
} | |
func saySomething() { | |
print("Hi!") | |
} | |
} | |
if let classType = NSClassFromString("APPNAMEORMODULE.YourClass") as? YourClass.Type { | |
let object = classType.init() | |
object.saySomething() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment