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 trialStephen Gehring
11,203 Pointsself.humidityLabel.text = "\(currentWeather.humidity)" renders Optional(0.82)
All my text labels are rendering the value wrapped in a Optional(0.82)?
2 Answers
Daniel Reedy
25,284 PointsIn 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 ...
}
Brock Ormond
7,176 PointsIf 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.
Stephen Gehring
11,203 Pointsthank you for the "(currentWeather.humidity!)" example