Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NamedShape {
- var numberOfSides: Int = 0
- var name: String
- init(name: String) {
- self.name = name
- }
- func simpleDescription() -> String {
- return "A shape with \(numberOfSides) sides."
- }
- }
- class Circle: NamedShape {
- var radius: Double
- init(radius: Double, name: String) {
- self.radius = radius
- super.init(name: name)
- }
- var area: Double {
- get {
- return Double.pi * pow(radius, 2)
- }
- set {
- radius = sqrt(area / Double.pi)
- }
- }
- override func simpleDescription() -> String {
- return "A circle with radius \(radius)"
- }
- }
- let test = Circle(radius: Double(10), name: "my test circle")
- test.area
- test.simpleDescription()
- test.area = 90
- test.radius // shouldn't this set radius to a new value? the playground is still returning 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement