Daily iOS
Architecture

Request state machine

A screen with a network request has loading, success, failure, retry, refresh, and cancel states all tangled together. How do you design those state transitions?

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

Define the state as an enum with associated values (idle/loading/loaded(data, isRefreshing)/failed(error, lastData)), and decide transitions in one place only, a (state, event) → state function.

Share a question