Daily iOS
SwiftUI

Data flow design

Using the single source of truth principle in SwiftUI, how do you decide which view should own a given piece of state?

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

State is owned in one place by the closest common ancestor of the views that need it (@State or @Observable), and every other view only references it. State shared between siblings gets lifted up to the parent.

Share a question