"AJAX Basics (retiring)" was retired on February 5, 2020. You are now viewing the recommended replacement.

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 Updating the Quantity

Stijn van Lieshout
Stijn van Lieshout
3,646 Points

Why call updateTotalPriceLabel() inside reset method?

I'm wondering why you'd call the updateTotalPriceLabel method inside the reset function? When selecting a new item, total price will also update without it, so why bother?

func reset() {
    quantity = 1
    updateQuantityLabel()
    updateTotalPriceLabel() 
}

1 Answer

David Lin
David Lin
35,864 Points

You are right, though updateTotalPriceLabel seems to belong in the reset() method, in case it is used elsewhere. Perhaps the best thing to do is remove the extra updateTotalPriceLabel() call in the collectionView.didSelectItemAtIndexPath method, since it is redundant if reset() is also called.