Daily iOS
SwiftUI

Reusable component design

You're building a design system's card component in SwiftUI to reuse across many screens. When would you use each approach (a custom View, a ViewModifier, a Style protocol, and so on), and by what criteria?

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 container that holds content is a generic View with @ViewBuilder; putting only a style on an existing view is a ViewModifier plus a View extension; the appearance of standard controls like Button and Toggle is a Style protocol such as ButtonStyle. Theme values are injected through the environment.

Share a question