Pick the fix
Ten screens repeat the same padding, background and corner radius. Which reuse approach is best?
Hint 1 of 1
Which option keeps the concrete view type?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A CardStyle: ViewModifier plus extension View { func cardStyle() -> some View }
Correct. It is reusable and keeps concrete types.
Why not the others?
- B A function that returns
AnyView(content.padding()...). It works, but type erasure hides structure from SwiftUI's diffing. - C Copy the modifiers into each screen. Ten copies drift apart over time.
- D Subclass a base view. SwiftUI views are structs; there is no inheritance.