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 Using the Vending Machine Testing Out the Vending Machine

jordon beyond
jordon beyond
2,158 Points

Quantity problem in Vending Machine code

unresolved identifier: Quantity

jordon beyond
jordon beyond
2,158 Points
 @IBAction func purchase() {
        if let currentSelection = currentSelection{
            do {
                try vendingMachine.vend(selection: currentSelection, quantity: quantity )
            }catch{
                //FIXME: ERROR HANDLING CODE
            }
        }else {
            //FIXME: ALERT USER TO NO SELECTION
        }
    }

Use of unresolved identifier 'quantity' Do you mean QuantityLabel? I checked on the VendingMachine.swift file and changed the func vend() accordingly, any one else have the same problem ?

protocol VendingMachine{
    var selection: [VendingSelection] { get }
    var inventory: [VendingSelection: VendingItem] { get set }
    var amountDeposited: Double { get set }

    init(inventory: [VendingSelection: VendingItem])

    func vend (selection: VendingSelection, quantity: Int) throws
    func deposit (_ amount: Double)
}
Patrick Duhamel
Patrick Duhamel
5,786 Points

In your ViewController.swift, did your declare a variable named quantity as shown at 0:52 of the video?

2 Answers

Gavin Hobbs
Gavin Hobbs
5,205 Points

Hey jordon beyond I'm running into the same bug. Patrick Duhamel what video did you mean when you said...

did your declare a variable named quantity as shown at 0:52 of the video?

Gavin Hobbs
Gavin Hobbs
5,205 Points

I asked the question with all my code attached and I got an answer that fixed my bug! Here's a link to that forum post... My bug was on line 24 in ViewController.swift. I needed to declare:

var quantity = 1