Swift類(lèi)中的錯(cuò)誤:在super.init調(diào)用時(shí)未初始化屬性我有兩節(jié)課,Shape和Squareclass Shape {
var numberOfSides = 0
var name: String
init(name:String) {
self.name = name }
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."
}}class Square: Shape {
var sideLength: Double
init(sideLength:Double, name:String) {
super.init(name:name) // Error here self.sideLength = sideLength
numberOfSides = 4
}
func area () -> Double {
return sideLength * sideLength }}通過(guò)上面的實(shí)現(xiàn),我得到錯(cuò)誤:property 'self.sideLength' not initialized at super.init call super.init(name:name)為什么我必須self.sideLength在打電話(huà)前設(shè)置super.init?
Swift類(lèi)中的錯(cuò)誤:在super.init調(diào)用時(shí)未初始化屬性
慕標(biāo)琳琳
2019-08-01 16:24:25