Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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...