0Pricing
SwiftUI Academy · Lesson

Toggling Visibility with State

Show or hide views using a boolean state.

Show and Hide on Demand

A boolean @State can decide whether a view is visible. Flip it and SwiftUI shows or hides content for you. 👀

@State private var isVisible = false

Conditional Views

Inside body you can use a plain if statement. When the condition is true, SwiftUI includes the view; when false, it leaves it out.

if isVisible {
    Text("Now you see me")
}

All lessons in this course

  1. Why Views Need State
  2. Declaring @State Properties
  3. Building a Tap Counter
  4. Toggling Visibility with State
← Back to SwiftUI Academy