Daily iOS
App lifecycle and system

View controller appearance lifecycle

In a UIKit screen, which pair of lifecycle methods would you add and remove a subscription in, like a NotificationCenter observer you only need while the screen is visible?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A subscription you only need while the screen is visible goes in a pair that's called the same number of times. Add in viewWillAppear and remove in viewWillDisappear, or use the didAppear and didDisappear pair to stay clear of the transition animation, and the subscription is never doubled or missing when the screen comes back after a trip away.

Share a question