0Pricing
SwiftUI Academy · Lesson

Running Code on Tap

Print, count, and trigger logic from a tap.

The Action Is Yours

The closure inside a button is where your app does real work. This is where you run logic, update data, or kick off a task on tap. ⚡

Printing for a Quick Test

The simplest action is a print. It writes to Xcode's console so you can confirm a tap was registered while you build.

Button("Test") {
    print("Button was tapped")
}

All lessons in this course

  1. Creating a Tappable Button
  2. Styling Buttons
  3. Running Code on Tap
  4. Disabling & Enabling Buttons
← Back to SwiftUI Academy