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.


I always get error message Type 'VendingMachine' does not conform to protocol 'VendingMachineType'

// // VendingMachine.swift // VendingMachine // // Created by Jatinder Singh Saini on 15/06/16. // Copyright © 2016 Treehouse. All rights reserved. //

import Foundation

protocol VendingMachineType { var selection : [VendingSelection] { get } var inventory : [VendingSelection : ItemType] { get set } var amountdeposited: Double { get set }

init(inventory :[VendingSelection : ItemType])
func vend(selection: VendingSelection, quantity :Double ) throws
func deposit(amount : Double)


protocol ItemType { var price :Double { get} var quantity : Double { get set}


enum InventoryError :ErrorType {

case InvalidResource
case ConversionError
case InvalidKey


class PlistConverter { class func dictionayFromfile(resource: String, OfType type: String ) throws -> [String :AnyObject] { guard let path = NSBundle.mainBundle().pathForResource(resource, ofType: type)else { throw InventoryError.InvalidResource


    guard let dictionary = NSDictionary(contentsOfFile: path),let castDictionary = dictionary as? [String:AnyObject] else {
        throw InventoryError.ConversionError


    return castDictionary

} class InventoryUnarchiver{ class func vendingInventoryFromDictionary(dictionary: [String : AnyObject]) throws -> [VendingSelection:ItemType]{

    var inventory: [VendingSelection : ItemType] = [:]

    for (key,value) in dictionary {
        if let itemDict = value as? [String :Double],
            let price = itemDict["price"], let quantity  = itemDict["quantity"] {
        let item = VendingItem(price: price, quantity: quantity)
            guard let key =  VendingSelection(rawValue: key) else {
                throw InventoryError.InvalidKey
            inventory.updateValue(item, forKey: key)


return inventory

} } enum VendingSelection : String { case Tea case Coffee case Coke case Maggi case SamoseCholle case BillUnits case CandyBar case Holidays }

struct VendingItem : ItemType { let price : Double var quantity :Double }

class VendingMachine: VendingMachineType {

let selection: [VendingSelection] = [.Tea, .Coffee, .Coke, .Maggi, .SamoseCholle, .BillUnits, .CandyBar, .Holidays]

var inventory: [VendingSelection : ItemType]
var amountDeposited: Double = 100.0

required init(inventory : [VendingSelection :ItemType]) {
    self.inventory = inventory

func  vend(selection: VendingSelection, quantity: Double) throws {


func deposit(amount: Double) {



2 Answers

Mohamed Moukhtar
Mohamed Moukhtar
Courses Plus Student 6,151 Points

The name of property "amount deposited" in the protocol declaration doesn't match the class declaration. You named it once (in the protocol) like this: "amountdeposited" while in the class declaration you named it like this: "amountDeposited". Use the same name and you are good to go.

its working now ! Thank you bro for helping me out