​Quick is really a effective and spontaneous programming language for macOS, iOS, watchOS and ...

Page 124

Swift

} } let NewCounter = Samplepgm() NewCounter.counter = 100 NewCounter.counter = 800 When we run the above program using playground, we get the following result: Total Counter is: 100 Newly Added Counter 100 Total Counter is: 800 Newly Added Counter 700

Local and Global Variables Local and global variable are declared for computing and observing the properties. Local Variables Variables that are defined within function, method, or closure context.

Global Variables a

Variables that are defined outside function, method, closure, or type context.

Used to store and retrieve values.

Used to store and retrieve values.

Stored properties is used to get and set the values.

Stored properties is used to get and set the values.

Computed properties are also used.

Computed properties are also used.

Type Properties Properties are defined in the Type definition section with curly braces {} and scope of the variables are also defined previously. For defining type properties for value types 'static' keyword is used and for class types 'class' keyword is used.

Syntax struct Structname { static var storedTypeProperty = " " static var computedTypeProperty: Int { // return an Int value here } } 112


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