​Fast is really a strong and instinctive development language for macOS, iOS, watchOS and tvOS...

Page 143

Swift

return "of rectangle for \(radius) " } }

class Rectangle: Circle { var print = 7 override var area: String { return super.area + " is now overridden as \(print)" } }

let rect = Rectangle() rect.radius = 25.0 rect.print = 3 println("Radius \(rect.area)") When we run the above program using playground, we get the following result: Radius of rectangle for 25.0 is now overridden as 3

Overriding Property Observers When a new property needs to be added for an inherited property, 'property overriding' concept is introduced in Swift. This notifies the user when the inherited property value is altered. But overriding is not applicable for inherited constant stored properties and inherited read-only computed properties. class Circle { var radius = 12.5 var area: String { return "of rectangle for \(radius) " } }

class Rectangle: Circle { var print = 7 override var area: String { return super.area + " is now overridden as \(print)" 131


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