Design an iOS Timer App with Consistent State and Asynchronous UI Updates
Company: Robinhood
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: easy
Interview Round: Technical Screen
Design and implement the structure of a small iOS timer application, focusing on state management, UI updates, and asynchronous work. Explain how time is represented, how user actions change the state, and how the interface stays consistent as callbacks and app lifecycle events occur.
### Constraints
The timer's exact product behavior is unspecified. Clarify whether it is a stopwatch, countdown, or interval timer before implementing it. UIKit or SwiftUI and Swift or Objective-C are acceptable; choose one combination and explain it consistently. This is a platform-specific implementation discussion rather than a portable algorithm console.
### Clarifying Questions
- Which actions are required: start, pause, resume, reset, or setting a duration?
- Should elapsed time include periods when the app is backgrounded or the device sleeps?
- Does state need to survive process termination, and is any notification required?
- How precise must the display be, and what should happen if callbacks are delayed?
```hint A callback is a refresh opportunity
Count elapsed time using a clock and recorded state rather than assuming every scheduled callback fires exactly on time.
```
### What a Strong Answer Covers
- A clear timer state machine and a single source of truth.
- Clock-based elapsed-time calculation, main-thread UI updates, and callback lifecycle management.
- Defined behavior for delayed callbacks, repeated actions, backgrounding, and view recreation.
### Follow-up Questions
- How would you prevent duplicate timer subscriptions after repeated view appearances?
- How would a countdown prevent its completion action from firing twice?
Overview: Design an iOS timer around explicit state transitions, clock-based elapsed time, main-thread UI updates, callback ownership, and lifecycle behavior.