Challenge - 5 Problems
Slider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Slider Value Change Behavior
What will be the value of the label text after moving the slider to 0.75 in this SwiftUI code?
iOS Swift
struct ContentView: View {
@State private var sliderValue: Double = 0.5
var body: some View {
VStack {
Slider(value: $sliderValue, in: 0...1)
Text(String(format: "%.2f", sliderValue))
}
}
}Attempts:
2 left
💡 Hint
Look at how the slider value is formatted in the Text view.
✗ Incorrect
The slider value is a Double between 0 and 1. The Text uses String(format: "%.2f", sliderValue) which formats the number with two decimal places. So 0.75 becomes "0.75".
❓ lifecycle
intermediate2:00remaining
Slider State Update Timing
In UIKit, when using UISlider with addTarget for .valueChanged, when is the action method called?
Attempts:
2 left
💡 Hint
Think about how UISlider reports changes as the user moves the thumb.
✗ Incorrect
The .valueChanged event fires continuously as the slider thumb moves, so the action method is called every time the value changes during dragging.
📝 Syntax
advanced2:00remaining
Correct SwiftUI Slider Binding Syntax
Which option correctly binds a slider value to a @State variable in SwiftUI?
iOS Swift
struct ContentView: View {
@State private var volume: Double = 0.3
var body: some View {
Slider(value: /* fill here */, in: 0...1)
}
}Attempts:
2 left
💡 Hint
Remember how to pass a binding to a SwiftUI control.
✗ Incorrect
In SwiftUI, to bind a control to a @State variable, you pass the binding using the $ prefix. So $volume is correct.
🔧 Debug
advanced2:00remaining
Why Slider Value Does Not Update Label
Given this SwiftUI code, why does the label not update when the slider moves?
struct ContentView: View {
var sliderValue: Double = 0.5
var body: some View {
VStack {
Slider(value: $sliderValue, in: 0...1)
Text(String(format: "%.2f", sliderValue))
}
}
}
Attempts:
2 left
💡 Hint
Check how SwiftUI tracks changes in variables.
✗ Incorrect
Without @State, SwiftUI does not track changes to sliderValue, so the UI does not update when the slider moves.
🧠 Conceptual
expert3:00remaining
Accessibility for Slider in SwiftUI
Which approach best improves accessibility for a slider controlling volume in SwiftUI?
Attempts:
2 left
💡 Hint
Think about how screen readers describe controls.
✗ Incorrect
Adding .accessibilityLabel and .accessibilityValue helps screen readers announce the slider purpose and current value clearly.