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 trialNila Palmo Ram
4,303 PointsError: Type 'Item' does not conform to protocol 'VendingItem'
protocol VendingItem {
var price: Double { get }
var quantity: Int { get set }
}
protocol VendingMachine {
var selection: [VendingSelection] { get }
var inventory: [VendingSelection: VendingItem] { get set }
var amountDeposited: Double { get set }
init(inventory: [VendingSelection: VendingItem]) //item type
func vend(selection: VendingSelection, quantity: Int) throws
func deposit(_amount: Double)
func item(forSelection selection: VendingSelection) -> VendingItem?
}
struct Item : VendingItem {
let price: Double
let quantity: Int
}
1 Answer
pierreilyamukuru
9,831 PointsIn your struct change let quantity to var quantity. This is because quantity is get and set. Solution: struct Item : VendingItem { var quantity: Int let price: Double