Page 163

Swift Subclass initializer cannot delegate up to the superclass initializer when overriding a failable superclass initializer with a non-failable subclass initialize. A non-failable initializer can never delegate to a failable initializer. The program given below describes the failable and non-failable initializers. class Planet { var name: String

init(name: String) { = name }

convenience init() { self.init(name: "[No Planets]") } } let plName = Planet(name: "Mercury") println("Planet name is: \(")

let noplName = Planet() println("No Planets like that: \(")

class planets: Planet { var count: Int

init(name: String, count: Int) { self.count = count super.init(name: name) }

override convenience init(name: String) { self.init(name: name, count: 1) } } When we run the above program using playground, we get the following result: 151

​Quick is a effective and user-friendly coding language for macOS, iOS, watchOS and tvOS....  


Read more
Read more
Similar to
Popular now
Just for you