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

iOS Build a Vending Machine App in Swift 2.0 Loading Data From a Resource Finishing Touches

Keli'i Martin
Keli'i Martin
8,227 Points

Starter 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
MOD
Jason Anders
Treehouse Moderator 145,860 Points

I 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)
    }

:dizzy:

cc Pasan Premaratne

Keli'i Martin
Keli'i Martin
8,227 Points

Thanks. 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!

Keli'i Martin
Keli'i Martin
8,227 Points

Thanks, Pasan Premaratne! Keep up the good work!

Ali Kayhan
Ali Kayhan
3,331 Points

Just one typo: Inside the do block, the function name that has been called for declaring "inventory" should be vending*InventoryFromDictionary, not **Invertory*.