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

Need some help on this

Given a resource named "CrazyInformation.plist" located in the main application directory, first retrieve the path to this resource and assign the string to a constant named plistPath. Once you have the plistPath, create an instance of NSDictionary containing the contents of the plist.

plist.swift
import Foundation

3 Answers

Hi MUZ, so I just spent the entire day trying to figure out this problem and after many frustrations I managed to get the answer. There are 2 parts in this problem (if any MOD reads my answer, I would suggest to split it into 2 sections; this way we know we are on the right track):

For the first part that says: "Given a resource named "CrazyInformation.plist" located in the main application directory, first retrieve the path to this resource and assign the string to a constant named plistPath." The solution is pretty simple and is exactly the same as shown in the video:

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

}

The second part asks: Once you have the plistPath, create an instance of NSDictionary containing the contents of the plist. This was definately the hardest and most confusing part. Probably what is not clear is that we have to create the instance INSIDE our plistPath; so I decided to try it out:

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

Notice that there is nothing that was not covered in the previous videos in this code; however, I think the confusion comes from organizing the code and putting it in the right place. I hope this helps and you did not bang your head against the desk as much as I did trying to figure this out.

Chris Howie
Chris Howie
13,216 Points

Cesar, thank you so much for breaking this down, I probably spent a day looking at this problem. I pretty much gave up until I saw an answer on the forum.

J Kim
J Kim
15,218 Points

Clear and informative instructions do not hurt. I am all for figuring out yourself & learning from the experience... but I am NOT A BIG FAN of needlessly wasting time because of poorly written instructions...