1
我有以下代碼:選配在超引起子類的初始化問題
class Being {
var age: Int?
}
class Person: Being {
var name: String
enum gender { case male, female }
var gender: gender
init(age: Int, name: String, gender: gender) {
super.init() // Error: Property 'self.name' not initialized at super.init call
super.age = age
self.name = name
self.gender = gender
}
}
但調用super.init()
之前初始化self.name
產生另一個錯誤(自我beefore super.init調用中使用)