Skip to content

Instantly share code, notes, and snippets.

@imthath-m
Last active March 31, 2020 04:55
Show Gist options
  • Save imthath-m/b516d3cdfb8a9e0a4a2bcf5a6ea076a6 to your computer and use it in GitHub Desktop.
Save imthath-m/b516d3cdfb8a9e0a4a2bcf5a6ea076a6 to your computer and use it in GitHub Desktop.
@objc class SuperClassA: NSObject {
public required override init() { }
public static var shared: SuperClassA {
if let instance = _shared {
return instance
}
return instance
}
public static var _shared: SuperClassA?
private static var instance: SuperClassA {
if let subClassB = NSClassFromString("ModuleB.SubClassB") as? SuperClassA.Type {
_shared = subClassB.init()
} else {
_shared = SuperClassA()
}
return _shared!
}
func sampleFunction() {
print("super class from module A")
}
}
// ModuleB
class SubClassB: SuperClassA {
required init() { }
override func sampleFunction() {
print("sub class from module B")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment