​Swift is just a effective and user-friendly development language for macOS, iOS, watchOS and ...

Page 187

Swift The optional values for subscripts can be accessed by referring their subscript values. It can be accessed as subscript[0], subscript[1] etc. The default subscript values for 'radius' are first assigned as [35, 45, 78, 101] and for 'Circle' [90, 45, 56]]. Then the subscript values are changed as Radius[0] to 78 and Circle[1] to 45.

Linking Multiple Levels of Chaining Multiple sub classes can also be linked with its super class methods, properties and subscripts by optional chaining. Multiple chaining of optional can be linked: If retrieving type is not optional, optional chaining will return an optional value. For example if String through optional chaining it will return String? Value class rectangle { var print: circle? }

class circle { var area = [radius]() var cprint: Int { return area.count } subscript(i: Int) -> radius { get { return area[i] } set { area[i] = newValue } } func circleprint() { println("The number of rooms is \(cprint)") } var rectarea: circumference? }

class radius { let radiusname: String init(radiusname: String) { self.radiusname = radiusname } 175


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