Page 159

Swift

override init() { super.init() corners = 5 } }

let bicycle = pentagon() println("Pentagon: \(bicycle.description)") When we run the above program using playground, we get the following result: Rectangle: 4 sides Pentagon: 5 sides

Designated and Convenience Initializers in Action class Planet { var name: String

init(name: String) { self.name = name }

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

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

class planets: Planet { var count: Int init(name: String, count: Int) { self.count = count 147

​Fast is really a strong and intuitive coding language for macOS, iOS, watchOS and tvOS....  

Quick is a effective and instinctive programming language for macOS, iOS, watchOS and tvOS....

Advertisement