Reference types vs Value types
- Classes are Reference types
- Enum and Struct are Value types
Reference types: assignment means pointing to same address location
Value types: assignment means copy to the new thing.
- even if be declared by
letkeyword (means be constant), classes can be modified
struct, if it's be declared as constant with
letkeyword, it cannot be modified. It's still true if it's be declared as variable with
varkeyword. But in this case, you can modified it with
mutatingkeyword in function declaration
enumdoesn't have stored property, so it doesn't relate here.
deinit is only available for classes. Because classes are reference types, so they are concerned by Reference counting process.
only with struct, swift generates init methods base on properties.
only class supports inheritance.
only enum cannot contain a Stored Property. Stored Property là một property của class hoặc struct, có thể được gán giá trị (để phân biệt với computed property)