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

​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