The Main difference in Class and Structure Classes are reference types. Structures are value types. Classes have an inheritance that allows one class to inherit the characteristics of another. Structures do not support inheritance. Class ( R eference Types ) Reference Type When you copy a reference type, each instance shares the data. The reference itself is copied, but not the data it references. When you change one, the other changes too. Inheritance Classes have an inheritance that allows one class to inherit the characteristics of another. Initializer We have to define the initializer manually. Storage Class instances are stored on the heap. Thread Safe Classes are not fully thread − safe. Example : class EmployeeList { var name: String var age: Int init(name: String, age: Int) { self.name = name self.grade = grade } } let emp1 = EmployeeList(name: "Dixit Akabari", age: 27) let emp2 = emp1 emp2.name = "M
Dixit Akabari | Tutorials for iPhone & iOS Developers