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 trialAdam Young
4,147 PointsApp crashing when launching
Hi,
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 {
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)
}
override func didReceiveMemoryWarning() {
super.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
}
Thanks,
Adam
2 Answers
Gabriel Mititelu
5,881 PointsHi.
You might have set a breaking point without noticing. Press "⌃⌘Y" to continue. If you have any error message logged out, paste it here.
Gabriel Mititelu
5,881 PointsHi, 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. :)
Adam Young
4,147 PointsAdam Young
4,147 PointsHi,
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