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

David Elliott
2,343 Pointsexersize not working
import Foundation
// Add your code below let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") let dictionary = NSDictionary(contentsOfFile: plistPath!)
//this code throws an error in the website but works fine in my xcode project
import Foundation
// Add your code below
let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist")
let dictionary = NSDictionary(contentsOfFile: plistPath!)
4 Answers

agreatdaytocode
24,757 PointsHi David,
I confirmed it still works. Check out this answer by Martin Wildfeuer.

David Elliott
2,343 PointsHi Aaron, Thanks for checking. The answer you link to suggests I answer in the same way that I did. Thats why I thought it was a bug in the website. oh well

agreatdaytocode
24,757 PointsDid you try adding it to a If statement?
if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") {
let dictionary = NSDictionary(contentsOfFile: plistPath)
}

David Elliott
2,343 PointsI didn't, force unwrap should be the same thing right?

agreatdaytocode
24,757 PointsIt should. But it's not. So try the If statement to get past it :) I'll send a note to the support team, asking them to take a look at this challenge.

Pasan Premaratne
Treehouse TeacherHey David Elliott,
Force unwrapping isn't really the same thing. It's only the same when you have the right path. If your resource doesn't exist and you force unwrap that will cause a crash.
In this particular case the error message should be notifying you of that (since there isn't actually a CrazyInformation.plist in the directory). I'll take a look at that and get it sorted

agreatdaytocode
24,757 PointsThank you for clearing that up for us Pasan Premaratne

David Elliott
2,343 PointsPasan Premaratne thanks that makes sense. I assumed that the force unwrap would be equivalent to conditional assignment since I also assumed that there was a CrazyInformation.plist in the directory.