​Swift is really a effective and instinctive development language for macOS, iOS, watchOS and ...

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


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.