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 trialJoe Hill
15,063 PointsVendingMachine.inventory not working in ViewController.swift
Ok so I went through the tutorial and around the 8:00 mark he goes into the ViewController.swift and has us write a print statement at the end of the init method, but I keep getting an error:
Instance member "inventory" cannot be used on type "Vending Machine"
I can't get it my app to work from here. Can anyone help? My code Snippet is below.
let vendingMachine: VendingMachine
required init?(coder aDecoder: NSCoder) {
do {
let dictionary = try PlistConverter.dictionary(fromFile: "VendingInventory", ofType: plist)
let inventory = try InventoryUnarchiver.vendingInventory(fromDictionary: dictionary)
self.vendingMachine = FoodVendingMachine(inventory: inventory)
} catch let error {
fatalError("\(error)")
}
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
setupCollectionViewCells()
print(VendingMachine.inventory)
1 Answer
Joe Hill
15,063 PointsThe "" around plist
was correct! Thanks!
Anthony Lafont
17,075 PointsAnthony Lafont
17,075 PointsHey Joe, I don't have the same error than you, when I copy/paste it in my code but I can see in this line
let dictionary = try PlistConverter.dictionary(fromFile: "VendingInventory", ofType: plist)
that it should be
let dictionary = try PlistConverter.dictionary(fromFile: "VendingInventory", ofType: "plist")
But I'm not sure it will solve you problem. Can you try it and tell me what's going on?