Page 225


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


​Quick is a effective and user-friendly coding language for macOS, iOS, watchOS and tvOS....  


Read more
Read more
Similar to
Popular now
Just for you