Page 225

Swift

class sides { var rectsides: Int init(rectsides: Int) { self.rectsides = rectsides } }

let objects: [AnyObject] = [Circle(radius: 2.0),result(area: 198),sides(rectsides: 4)]

for object in objects { if let objectWithArea = object as? rectangle { println("Area is \(objectWithArea.area)") } else { println("Rectangle area is not defined") } } When we run the above program using playground, we get the following result: Area is 12.5663708 Area is 198.0 Rectangle area is not defined

213

​Quick is really a powerful and intuitive programming language for macOS, iOS, watchOS and tvO...  

...

Advertisement