Google News
logo
Swift - Interview Questions
What are some features that Swift classes can support but Swift structs cannot?
Given below are some features which Swift classes can support but Swift structs cannot :
 
* To develop our own custom view controller subclasses, we can inherit from another class, such as UIViewController. This cannot be achieved using Swift structs.

* Before a class is destroyed, it can be deinitialized by calling the deinit() function. This cannot be done for Swift structs.

* Structures are value types, while classes are reference types.

Value Types : When you copy a value type (for example, when it is assigned, initialised, or passed into a function), each instance preserves its own copy of the data. If you update one instance, it does not affect the other.

Reference Types : When you copy a reference type, the data is shared among all instances. The reference is copied, but the data it refers to is not. When one is altered, the other is altered as well.
Advertisement