Bird
0
0

What will be displayed if the following SwiftUI code runs and the user taps the minus button once?

medium📝 Predict Output Q5 of 15
iOS Swift - User Input and Forms
What will be displayed if the following SwiftUI code runs and the user taps the minus button once?
@State private var value = 3
Stepper("Value", value: $value, in: 1...5)
Text("Current: \(value)")
ACurrent: 1
BCurrent: 3
CCurrent: 0
DCurrent: 2
Step-by-Step Solution
Solution:
  1. Step 1: Check initial value and range

    Initial value is 3, allowed range is 1 to 5.
  2. Step 2: Apply one minus tap

    Decreasing 3 by 1 gives 2, which is within range.
  3. Final Answer:

    Current: 2 -> Option D
  4. Quick Check:

    Stepper decrements within range correctly [OK]
Quick Trick: Stepper won't go below minimum range [OK]
Common Mistakes:
  • Assuming value stays same
  • Going below min range
  • Confusing plus and minus buttons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes