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 (Retired) Data Modeling With Structures Swift Initializers

Cillian Warfield
Cillian Warfield
15,020 Points

I'm getting an error "Use of unresolved identifier 'weatherDictionary'".

Here's my init code:

init(weatherDicitionary: NSDictionary) { let currentWeather = weatherDictionary["currently"] as NSDictionary }

3 Answers

Stone Preston
Stone Preston
42,016 Points

you misspelled dictionary in the init parameter

//weatherDictionary is misspelled
init(weatherDicitionary: NSDictionary) {
        let currentWeather = weatherDictionary["currently"] as NSDictionary
 }

it should be

init(weatherDictionary: NSDictionary) {
        let currentWeather = weatherDictionary["currently"] as NSDictionary
 }
Cillian Warfield
Cillian Warfield
15,020 Points

thanks for the quick answer. Unfortunately, I'm still getting the same error even with the spelling correction.

Here's my code from my view "controller.swift" that refers to the weatherDictionary.

if (error == nil){ let dataObject = NSData(contentsOfURL: location) println("dataObject: (dataObject)") let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary }

Does this code have anything to do with the "weatherDictionary" in my original question or is the weatherDictionary in the init method only a local constant that only exists in the init method?

Stone Preston
Stone Preston
42,016 Points

is the weatherDictionary in the init method only a local constant that only exists in the init method?

the weatherDictionary in the init method is only scoped to the init method, so yes it only exists in the init method.

the error is definitely in this code correct?

init(weatherDictionary: NSDictionary) {
        let currentWeather = weatherDictionary["currently"] as NSDictionary
 }

you might try adding the other code that the video adds after that first line and see if you still get the same error. there isnt anything wrong with the code above really, except that at that point not all of the properties have been initialized so you will have to do that

Cillian Warfield
Cillian Warfield
15,020 Points

Hi, Thanks for your help. Just getting back to this now. When I copy pasted your code above (and commented out my code) it worked! But then comparing the two bits of code I couldn't see any differences between them. I then went back to my typed code and when I erased the spacing of the second line of code and then "tabbed" the line back into position the error disappeared. Can it be that the code is really that sensitive to spaces and tabs? It's a bit daunting for a noob such as me, when the code seems to ok but still is giving errors! Anyway all sorted now. Thanks.