Browse Questions
- The core difference is value type vs reference type.
- SPM is Apple's built-in dependency manager for Swift.
- Generate the pair with TSKeyGen, then persist only the private key in the Keychain with a restrictive accessibility class and hand the public key to the server during enrolment.
- Delegation is a pattern where one object hands off responsibility to another through a protocol, letting a child communicate back to its owner without knowing its concrete type.
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