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) Displaying Our Weather Data Connecting the UI to Our Model

self.humidityLabel.text = "\(currentWeather.humidity)" renders Optional(0.82)

All my text labels are rendering the value wrapped in a Optional(0.82)?

2 Answers

In the Current.swift class file you might have made some of the variables optional.

It should looks something like this:

// ... import stuff ...

struct Current {

  var currentTime: String?
  var temperature: Int // Make sure this isn't set as optional, no ? at the end
  var humidity: Double 
  var precipProbability: Double
  var summary: String
  var icon: UIImage?

  // ... rest of the implementation ...
}

If the variable is supposed to be optional, but you wanted to print the value if it had one then you need to '!' the variable first to just get the value...

self.humidityLabel.text = "(currentWeather.humidity!)"

although you'd want to wrap it in an if-statement in case it was nil.

thank you for the "(currentWeather.humidity!)" example