<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Stepper/init(_:onIncrement:onDecrement:onEditingChanged:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI7StepperVA2A4TextVRszrlE_11onIncrement0E9Decrement0E14EditingChangedACyAEG10Foundation23LocalizedStringResourceV_yycSgAMySbctcfc::OverloadGroup"
  },
  "title" : "init(_:onIncrement:onDecrement:onEditingChanged:)"
}
-->

# init(_:onIncrement:onDecrement:onEditingChanged:)

Creates a stepper that uses a title key and executes the closures
you provide when the user clicks or taps the stepper’s increment and
decrement buttons.

```
@export(implementation) nonisolated init(_ titleResource: LocalizedStringResource, onIncrement: (() -> Void)?, onDecrement: (() -> Void)?, onEditingChanged: @escaping (Bool) -> Void = { _ in })
```

## Parameters

`titleResource`

Text resource for the stepper’s localized title
describing the purpose of the stepper.

`onIncrement`

The closure to execute when the user clicks or taps
the control’s plus button.

`onDecrement`

The closure to execute when the user clicks or taps
the control’s minus button.

`onEditingChanged`

A closure that’s called when editing begins and
ends. For example, on iOS, the user may touch and hold the
increment or decrement buttons on a `Stepper` which causes the
execution of the `onEditingChanged` closure at the start and end of
the gesture.

## Discussion

Use this initializer to create a stepper with a custom title that
executes closures you provide when either of the stepper’s increment
or decrement buttons are pressed. This version of [`Stepper`](/documentation/SwiftUI/Stepper) doesn’t
take a binding to a value, nor does it allow you to specify a range of
acceptable values, or a step value – it simply calls the closures you
provide when the control’s buttons are pressed.

The example below uses an array that holds a number of [`Color`](/documentation/SwiftUI/Color) values,
a local state variable, `value`, to set the control’s background
color, and title label. When the user clicks or taps on the stepper’s
increment or decrement buttons SwiftUI executes the relevant
closure that updates `value`, wrapping the `value` to prevent overflow.
SwiftUI then re-renders the view, updating the text and background
color to match the current index:

```
struct StepperView: View {
    @State private var value = 0
    let colors: [Color] = [.orange, .red, .gray, .blue, .green,
                           .purple, .pink]

    func incrementStep() {
        value += 1
        if value >= colors.count { value = 0 }
    }

    func decrementStep() {
        value -= 1
        if value < 0 { value = colors.count - 1 }
    }

    var body: some View {
        Stepper("Value: \(value) Color: \(colors[value].description)",
                 onIncrement: incrementStep,
                 onDecrement: decrementStep)
        .padding(5)
        .background(colors[value])
    }
}
```

![A view displaying a stepper that uses a title resource for the](images/com.apple.SwiftUI/SwiftUI-Stepper-increment-decrement-closures@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)