Quick is just a effective and spontaneous coding language for macOS, iOS, watchOS and tvOS....

Page 111

19. Swift – Structures

Swift

Swift provides a flexible building block of making use of constructs as Structures. By making use of these structures once can define constructs methods and properties.

Unlike C and Objective C 

Structure need not require implementation files and interface.

Structure allows us to create a single file and to extend its interface automatically to other blocks.

In Structure the variable values are copied and passed in subsequent codes by returning a copy of the old values so that the values cannot be altered.

Syntax Structures are defined with a 'Struct' Keyword. struct nameStruct { Definition 1 Definition 2 --Definition N }

Definition of a Structure Consider for example, suppose we have to access students record containing marks of three subjects and to find out the total of three subjects. Here markStruct is used to initialize a structure with three marks as datatype 'Int'. struct MarkStruct{ var mark1: Int var mark2: Int var mark3: Int }

Accessing the Structure and its Properties The members of the structure are accessed by its structure name. The instances of the structure are initialized by the 'let' keyword. 99


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