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!

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

Adam Young
Adam Young
4,147 Points

App crashing when launching


I got to the end of the video where it was time to launch the project and it crashed upon launching. On line 37 (setupCollectionViewCells() ) it says Thread 1 breakpoint 2.1

I will paste my code below. I would appreciate it if someone can help me out.

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 {
    super.init(coder: aDecoder)

override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.

override func didReceiveMemoryWarning() {
    // Dispose of any resources that can be recreated.

// MARK: - UICollectionView 

func setupCollectionViewCells() {
    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
    let padding: CGFloat = 10
    layout.itemSize = CGSize(width: (screenWidth / 3) - padding, height: (screenWidth / 3) - padding)
    layout.minimumInteritemSpacing = 10
    layout.minimumLineSpacing = 10

    collectionView.collectionViewLayout = layout

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 12



2 Answers


You might have set a breaking point without noticing. Press "βŒƒβŒ˜Y" to continue. If you have any error message logged out, paste it here.

Adam Young
Adam Young
4,147 Points


This is what it says in the debug area:

self VendingMachine.ViewController 0x00007fb71073f360 UIKit.UIViewController UIViewController
collectionView UICollectionView! 0x00007fb712031a00 totalLabel UILabel! 0x00007fb710682f10 balanceLabel UILabel! 0x00007fb7104328c0 quantityLabel UILabel! 0x00007fb7106823f0 vendingMachine VendingMachine.VendingMachine 0x00007fb710743fe0

Thanks, Adam

Hi, Adam.

Unfortunately, that doesn't tell me much.

I took a second look at your code and compared it with the file the teacher provides and it seems like you're missing a few lines of code and one of them is wrong.

I recommend downloading the file, from the downloads section below the video, and compare. Even though it might take you 10-15 minutes to catch the error, I strongly encourage you to do so as these experiences will truly help you out in the future.

Best of luck. :)