Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Vending Machine App in Swift 2.0 Using the Vending Machine Working with Steppers

Wai Hong Low
Wai Hong Low
Courses Plus Student 6,859 Points

Regarding to the UIStepper, I think you need to create an IBOutlet for it so that the user can reset the value of it

The existing reset method only reset the var quantity in the view controller but not the stepper itself.

For example, if I selected item 1 , and increase the quantity to 5. Now I select item 2, when I try to increase the quantity , I expect it to be 2 since we have reset it back to 1 upon selecting a different item on the uicollectionview , but it shows 6 instead.

@IBAction func updateQuantity(sender: UIStepper) {
    quantity = sender.value

This method itself will take any value sent from the stepper, so it was 5 + 1 = 6. But it's not suppose to be that case.

So I think we need an extra IBOutlet as below:

@IBOutlet weak var quantityStepper: UIStepper!

and update the reset function like this:

func reset(){
    quantityStepper.value = 1
    quantity = 1