Type Safely

Type Safely

Use a Switch To Create a Value Inside a SwiftUI View's Body Property

Daily Coding Tip 289

Type Safely's avatar
Type Safely
Jun 16, 2023
∙ Paid
grey metal railway during daytime
Photo by Paul on Unsplash

It’s now possible to use if statements and switches wherever you are assigning a value.

Unfortunately (or perhaps fortunately) this does not work when passing a parameter, for instance to create the StringProtocol inside the initialiser for a Text view.

But since I can create local variables inside the view’s body property anyway…

User's avatar

Continue reading this post for free, courtesy of Type Safely.

Or purchase a paid subscription.
© 2026 Type Safely · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture