Type Safely

Type Safely

Share this post

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

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

Share this post

Type Safely
Type Safely
Use a Switch To Create a Value Inside a SwiftUI View's Body Property
Share
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…

Keep reading with a 7-day free trial

Subscribe to Type Safely to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Type Safely
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share