0Pricing
SwiftUI Academy · Lesson

Building a Tap Counter

Update state on tap and watch the UI refresh.

The Goal: A Live Counter

Let's build a button that counts your taps and shows the total on screen. It is the classic first taste of reactive state. 👆

Start with State

Begin with a single @State property to hold the running total. We name it count and start it at zero.

@State private var count = 0

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