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


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