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 trialKeli'i Martin
8,227 PointsStarter code doesn't have the required init
Just a heads up to Pasan. The starter code that I downloaded at the beginning of this course was different than you are showing. Specifically, the ViewController.swift file in the starter code I downloaded did NOT have the required init?()
in it. I had to double check and redownloaded a fresh zip file and, sure enough, no init()
in ViewController.swift.
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsI noticed that too. I had to jump through the video and pause at specific points to add the missing code to the starter files.
i.e. the required init?
and the super.init
lines of code.
This code snippet includes the missing lines of code and will get you up-to-speed for the end of the course.
let vendingMachine: VendingMachineType
required init?(coder aDecoder: NSCoder) {
do {
let dictionary = try PlistConverter.dictionaryFromFile("VendingInventory", ofType: "plist")
let inventory = try InventoryUnarchiver.vendingInventoryFromDictionary(dictionary)
self.vendingMachine = VendingMachine(inventory: inventory)
} catch let error {
fatalError("\(error)")
}
super.init(coder: aDecoder)
}
Keli'i Martin
8,227 PointsKeli'i Martin
8,227 PointsThanks. Yeah I had already gone back and added the code needed to finish the course. I should have added that to this post as well for others to get, but now that you have, others can get it!
Pasan Premaratne
Treehouse TeacherPasan Premaratne
Treehouse TeacherWhoops. Will fix this
Keli'i Martin
8,227 PointsKeli'i Martin
8,227 PointsThanks, Pasan Premaratne! Keep up the good work!
Pasan Premaratne
Treehouse TeacherPasan Premaratne
Treehouse TeacherShould be fixed!
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsAli Kayhan
3,331 PointsAli Kayhan
3,331 PointsJust one typo: Inside the do block, the function name that has been called for declaring "inventory" should be vending*InventoryFromDictionary, not **Invertory*.
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsThanks Ali Kayhan.
Typo correct.