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 Bootstrapping the UI

Andy Seavers
Andy Seavers
2,288 Points

currentTemperatureLabel?.text = "\(currentWeather.temperature)ΒΊ" doesn't work in Swift 2.1.1. Help?

The app won't build at this step.

4 Answers

Michael Reining
Michael Reining
10,101 Points

What error are you getting when you try to build this? It is working for me. In my code I have:

self.temperatureLabel.text = "\(currentWeather.temperature)ΒΊ"

Please note that you have to change the error handling for the JsonSerialization. Perhaps that is causing the error.

do {
                    if let weatherDictionary = try NSJSONSerialization.JSONObjectWithData(dataObject!, options: []) as? NSDictionary {
                        let currentWeather = Current(weatherDictionary: weatherDictionary)

                        dispatch_async(dispatch_get_main_queue(), { () -> Void in
                            self.temperatureLabel.text = "\(currentWeather.temperature)ΒΊ"
                            self.iconView.image = currentWeather.icon!
                            self.currentTimeLabel.text = "At \(currentWeather.currentTime!) it is"
                            self.humidityLabel.text = "\(currentWeather.humidity)"
                            self.precipitationLabel.text = "\(currentWeather.precipProbability)"
                            self.summaryLabel.text = "\(currentWeather.summary)"

                            //Stop refresh animation
                            self.refreshActivityIndicator.stopAnimating()
                            self.refreshActivityIndicator.hidden = true
                            self.refreshButton.hidden = false
                        })

                    }
                } catch let error as NSError {
                    print(error.localizedDescription)
                }

I hope that helps.

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app.

Code! Learn how to program with Swift

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Andy Seavers,

The reason it doesnt work is that Swift two introduces a new error model that requires you to handle possible errors thrown. Give Michael Reining's code snippet a try; it should work for you.

We have a course on error handling releasing later this month that goes into the whys. The Weather App is currently being re done to take the changes into account. You can read more about updates/timeline on Swift 2 stuff here

Andy Seavers
Andy Seavers
2,288 Points

Thanks Pasan. I was actually able to figure it out yesterday with a friend's help.

Giovanni Sylvestre
Giovanni Sylvestre
3,100 Points

i have Xcode 7 and when i added the property list file into the stormy folder it worked fine for me. i was adding it into the StormyTests folder before and it didn't work.

I am stuck here, can somebody paste solution?