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 trialGeorge W
2,697 PointsNot sure what to do with plistPath
I'm not really sure what i'm supposed to be doing in this because this code isn't working. Did I miss something? I even tried using the code from the weather project and modifying it but it hasnt worked. Please help. Thanks
import Foundation
// Add your code below
let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") as! String
let cazyDictionary = NSDictionary(contentsOfFile: plistPath)
1 Answer
Michael Reining
10,101 PointsHi George,
You are close. The challenge does not say so specifically but you are dealing with optionals here and the trick is to safely unwrap the optional. To unwrap an optional use if let like this.
// if let basically means
// if plistPath is not nil... then create the crazyDictionary
if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") {
let crazyDictionary = NSDictionary(contentsOfFile: plistPath)
}
I hope that helps. I created an app helping others learn swift and it includes a chapter on optionals that might help.
Mike
PS: Thanks to the awesome resources on Team Treehouse, I launched my first app.
carlton reid
266 Pointscarlton reid
266 PointsHello Im new to swift as well, can you also unwrap with the ? symbol
Michael Reining
10,101 PointsMichael Reining
10,101 PointsThe question mark does not unwrap an optional. An optional is a separate type. It says that something is either there or not. Once unwrapped, you either have a nil value or the real thing.
Here are two ways to unwrap an optional.
I hope that helps,
Mike