How it works
TupleSliderTickContent is the opaque container type that SwiftUI produces when you declare several tick marks together inside a slider's ticks closure. Each SliderTick you list is gathered, in order, into a single tuple-backed value that conforms to SliderTickContent, giving the slider a fixed set of snap positions and reference marks along its track. You rarely name this type yourself; reach for it implicitly whenever you want a slider to advance in discrete, labeled increments rather than slide continuously, and let the result builder assemble your marks into it.
Open a ticks closure on the slider
The ticks: trailing closure is the entry point: everything you place inside it is collected by a tick builder into a TupleSliderTickContent value that the Slider then renders along its track. In the example the closure follows the label closure on Slider(value: $volume, in: 0...1), so the marks share the slider's 0...1 range.
Declare each mark with SliderTick
Inside the closure, each SliderTick(_:) names one position in the slider's value range where a tick should appear and where the thumb can snap. The example lists SliderTick(0.0), SliderTick(0.25), SliderTick(0.5), SliderTick(0.75), and SliderTick(1.0) to mark the quarter points of the volume scale.
Let the builder combine the marks into one value
Because the closure holds more than one SliderTick, SwiftUI bundles them into a TupleSliderTickContent rather than passing a lone tick. This is the same builder pattern as TupleView: the count and order of your statements determine the tuple, so the five SliderTick calls become a single ordered collection of snap targets bound to $volume.
Drive a bound value through the ticks
The ticks constrain the value the slider writes back through its binding, so dragging settles on the nearest declared mark. Here the thumb snaps among 0.0, 0.25, 0.5, 0.75, and 1.0, and Text("Volume: \(Int(volume * 100))%") reports the resulting volume as a whole percentage.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TupleSliderTickContentDemo: View {
@State private var volume = 0.5
var body: some View {
VStack(spacing: 16) {
Text("Volume: \(Int(volume * 100))%")
.font(.headline)
Slider(value: $volume, in: 0...1) {
Text("Volume")
} ticks: {
SliderTick(0.0)
SliderTick(0.25)
SliderTick(0.5)
SliderTick(0.75)
SliderTick(1.0)
}
}
.padding()
}
}