You need to hide it.
I found a useful extension here:
https://stackoverflow.com/questions/56490250/dynamically-hiding-view-in-swiftui
If you prefer, could write another extension with isVisible ; but usual API is for hiding.
Now, your code becomes:
extension View {
/// Hide or show the view based on a boolean value.
@ViewBuilder func isHidden(_ hidden: Bool, remove: Bool = false) - some View {
if hidden {
if !remove {
self.hidden()
}
} else {
self
}
}
}
struct ContentView: View {
let exampleVariable = "Example"
func exampleFunc() {
print("Example")
}
var body: some View {
Text("Hello")
secondBody
.isHidden(stepNum = 4) // Condition to hide is opposite to condition to show
}
var secondBody: some View {
Text("World")
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: