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 Enumerations and Optionals in Swift Introduction to Optionals Optional Binding

Ryan Forte
seal-mask
.a{fill-rule:evenodd;}techdegree
Ryan Forte
iOS Development Techdegree Student 2,955 Points

optional binding not working

// optioinal binding


    let weatherDictionary: [String : [String : String]] = [
        "currently": ["temperature": "22.3"],
        "daily": ["temperature": "22.3"],
        "weekly": ["temperature": "22.3"]
]

    if let dailyWeather = weatherDictionary["daily"], let highTemperature = dailyWeather["temperature"] {
        print(highTemperature)
}

i get these errors come up: 4- expected decleration

  • variable used within its own intitial value

note: i have the latest version of xcode

Drew Carver
Drew Carver
5,189 Points

I tried to reproduce this, and I don't see any errors in the code. What line are you getting that error on?

Greg Kaleka
Greg Kaleka
39,021 Points

Copy/pasted your code and it worked fine for me as well.