Browse Questions
- An Optional is a type that can hold either a value or nil.
- Yes — passing an observed property as inout always calls both willSet and didSet, even if the function never modifies the value.
- The core difference is value type vs reference type.
- async let starts a child task immediately and lets you await its result later.
Answer: The core difference is value type vs reference type.
struct | class | |
|---|---|---|
| Type | Value type | Reference type |
| Memory | Stack (usually) | Heap |
| Inheritance | No | Yes |
| Mutability | Explicit (mutating) | Implicit |
| ARC | No | Yes |
deinit | No | Yes |
Rule of thumb:
- Use
structby default — safer, faster, no retain cycles - Use
classwhen you need identity, inheritance, or Objective-C interop