Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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