Unowned Variable Capture
Prefer capturing references as weak to avoid potential crashes
- Identifier:
unowned_variable_capture
- Enabled by default: No
- Supports autocorrection: No
- Kind: lint
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
foo { [weak self] in _ }
foo { [weak self] param in _ }
foo { [weak bar] in _ }
foo { [weak bar] param in _ }
foo { bar in _ }
foo { $0 }
final class First {}
final class Second {
unowned var value: First
init(value: First) {
self.value = value
}
}
Triggering Examples
foo { [↓unowned self] in _ }
foo { [↓unowned bar] in _ }
foo { [bar, ↓unowned self] in _ }