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

Schott Taylor
PLUS
Schott Taylor
Courses Plus Student 7,125 Points

Unsure what i did wrong on the little test here. Ive made sure that I'm retrieving the plist path. Any suggestions?

I have studied the previous videos and have implemented the described details. Making sure I'm finding the correct plist and storing it in a dictionary. It still gives me an error when I check work and I'm simply unsure where i went wrong. Help would be very appreciated.

plist.swift
import Foundation

// Add your code below

let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist")

 let crazyDictionary = NSDictionary(contentsOfFile: plistPath),
 let currentCrazyDictionary = crazyDictionary["currently"] as? [String: AnyObject]{

    let currentdictionary = CrazyInformation(crazyDictionary: currentCrazyDictionary)

 }

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Schott Taylor,

First you need to retrieve the path to the plist using NSBundle.mainBundle.pathForResource. You then use the retrieved path to create a NSDictionary using the contentsOfFile initializer and passing in the plistPath.

You're going to want to retrieve the plistPath using optional binding, because its possible that the retrieval will fail, and your returned path will be wrapped in an optional.

import Foundation

// Add your code below

if let plistPath = NSBundle.mainBundle().pathForResource("CrazyInformation", ofType: "plist") {
  let crazyDictionary = NSDictionary(contentsOfFile: plistPath) as? [String: AnyObject]
}

Hope this helps. Good Luck!