​Swift is just a strong and spontaneous coding language for macOS, iOS, watchOS and tvOS....

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


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