, , required init, , Types, . A protocol, init, .
, , init .
- , .
protocol ZeroParamaterInit {
init()
}
class Base : ZeroParamaterInit {
func launch(code1: Int, code2: Int) { }
required init() {
}
}
class A: Base {}
class B: Base {}
class C: Base {}
let classes : [ZeroParamaterInit.Type] = [A.self,B.self]
var instances : [Any] = []
for cls in classes {
let instance = cls.init()
instances.append(instance)
}
for instance in instances {
if let test = instance as? A {
print("A")
}
if let test = instance as? B {
print("B")
}
if let test = instance as? C {
print("C")
}
}