protocol TestProtocol {
init()
}
class Person: NSObject, TestProtocol {
required override init() {
super.init()
}
}
class Man: Person {
}
class Women: Person {
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let classes: [TestProtocol.Type] = [Person.self, Man.self, Women.self]
classes.forEach { (type) in
let obj = type.init()
print(obj)
}
}
}
I try to excute these codes in Xcode10.2, Swift version config to Swift5, I expect to get instances of Person, Man and Women, but the console result is:
<TestSwift5.Person: 0x6000006eb3e0>
<TestSwift5.Person: 0x6000006eb3e0>
<TestSwift5.Person: 0x6000006eb3e0>
which is confuse me, anyone can explain it.
looks forward your answer, thanks.