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

William Choi
William Choi
6,121 Points

Having trouble with the challenge

Dont know what to do/ what code I should add/take away

plist.swift
import Foundation

// Add your code below
let plistPath = "CrazyInformation.plist".plist

let NSDictionary = plistPath

1 Answer

Stephen McMillan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 Points

You access the plist path through the NSBundle method below. Also It's probably best to surround it in an 'if let' to ensure the plist inst nil and we don't crash when trying to access it.

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

}

Then to assign the contents of the file path to an NSDictionary you do: (Inside the 'if let' statement)

  let dictionary = NSDictionary(contentsOfFile: plistPath)

Looking at the NSBundle and NSDictionary sections of the docs helped me figure this out - so take a look there for more info.

Hope that helped. Good luck.

William Choi
William Choi
6,121 Points

This helped heaps, thanks alot mate.