Browse Questions
- Delegate protocols must inherit from AnyObject to restrict protocol conformance to classes, allowing delegate properties to be marked with the weak keyword.
- A retain cycle occurs when two objects hold strong references to each other, preventing ARC from deallocating either.
- Arrays and structs are value types, so changing anything inside them — appending, editing an element, or changing a nested field — counts as setting the whole property to a new value.
- Subscribe to keyboard notifications to adjust your layout when the keyboard appears or hides, so it doesn't cover your input fields.
Answer: A retain cycle occurs when two objects hold strong references to each other, preventing ARC from deallocating either. Memory leaks.
Common case — closure capturing self:
// ❌ Retain cycle — viewModel holds closure, closure holds viewModel
viewModel.onUpdate = {
self.updateUI() // strong capture
}
// ✅ Break cycle with [weak self]
viewModel.onUpdate = { [weak self] in
self?.updateUI()
}
// ✅ Or [unowned self] if self is guaranteed to outlive the closure
viewModel.onUpdate = { [unowned self] in
self.updateUI()
}
How to find them: Xcode's Memory Graph Debugger (Debug > Memory Graph) — look for objects that still exist after they should be deallocated.