Classes in Swift are similar to Structures in Swift. These are building blocks of flexible constructs. You can define class properties and methods like constants, variables and functions are defined. In Swift 4, you don't need to create interfaces or implementation files while declaring classes. Swift 4 facilitates you to create classes as a single file and the external interfaces will be created by default when the class is initialized.
Benefits of Swift Classes
Characteristics of Classes and Structures in Swift
In the following program there are two classes Salary and EmpSalary.
After running the above program, you will see the following output:
Employee salary is 10000
Note: In the above example, class properties are accessed by the '.' syntax. Property name is separated by a '.' after the instance name.
Class Identity Operators
Swift4 classes refer multiple constants and variables pointing to a single instance. To know about the constants and variables pointing to a particular class, instance identity operators are used. Class instances are always passed by reference. In Classes, NSString, NSArray, and NSDictionary instances are always assigned and passed around as a reference to an existing instance, rather than as a copy.
Identical to Operators
Not Identical to Operators
Next TopicSwift Properties