Explore Library
Code Quiz

View Controller Lifecycle Cleanup

Spot the lifecycle mismatch that leaks a timer and keeps the view controller alive.

Codeswift
class FeedViewController: UIViewController {
    var refreshTimer: Timer?

    override func viewDidLoad() {
        super.viewDidLoad()
        refreshTimer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
            self.reloadFeed()
        }
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        // clean up UI state
    }

    func reloadFeed() { /* fetch and update */ }
}

What is the bug in this view controller's lifecycle handling?