Quick is really a effective and intuitive programming language for macOS, iOS, watchOS and tvOS....

Page 132

Swift

val.scaleBy(3) val.scaleBy(30) val.scaleBy(300) When we run the above program using playground, we get the following result: 9 15 270 450 81000 135000

Self Property for Mutating Method Mutating methods combined with 'self' property assigns a new instance to the defined method. struct area { var length = 1 var breadth = 1

func area() -> Int { return length * breadth }

mutating func scaleBy(res: Int) { self.length *= res self.breadth *= res println(length) println(breadth) } } var val = area(length: 3, breadth: 5) val.scaleBy(13)

When we run the above program using playground, we get the following result.

120


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