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 Weather App with Swift Simple Data Structures Loading Files From A Directory

Owen Hughes
Owen Hughes
10,188 Points

Question not accepting correct answer

So, I'm trying to safely instantiate a dictionary from a plist as per the question, but it's not accepting my answer. I've also tried just using bangs to force unwrap like this:

```if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist")! let crazyDict = NSDictionary(contentsOfFile: plistPath)!

I've used the code just fine in an xcode project - am I missing something here?

```plist.swift
import Foundation

// Add your code below
if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist"),
let crazyDict = NSDictionary(contentsOfFile: plistPath) {

}
Owen Hughes
Owen Hughes
10,188 Points

To add context, this is the first code challenge in the "Build a weather app with Swift" course. I thought the question would be included in this post automatically.

2 Answers

Owen Hughes
Owen Hughes
10,188 Points

Got it

if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") { 
    let crazyDictionary = NSDictionary(contentsOfFile: plistPath)
}

Very ambiguously phrased question. Especially considering in the previous video, a similar problem was solved differently.

Thanks! Yeah, I was a little confused as to why it wouldn't work. Missing the if and {}

Unfortunately there are many ways to solve this and they wanted to see a specific way. The question needs to be more specific. Anyways your response helped me get past this code challenge so, thank you good sir!