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
Tukang Keboen
2,840 PointsDisplaying Image but icon weahter didn't change at all!!! why? "Displaying Image"
I have followed all the step in Mr Pasan video.. but my weather icon didn't change at all and no error found there... i stucked there over 4 days already.. please help me
Xcode 7 CurrentWeather code:
func toImage() -> UIImage? {
var imageName: String
switch self{
case .ClearDay:
imageName = "clear-day"
case .ClearNight:
imageName = "clear-night"
case .Rain:
imageName = "rain"
case .Snow:
imageName = "snow"
case .Sleet:
imageName = "sleet"
case .Wind:
imageName = "wind"
case .Fog:
imageName = "fog"
case .Cloudy:
imageName = "cloudy"
case .PartlyCloudyDay:
imageName = "cloudy-day"
case .PartlyCloudyNight:
imageName = "cloudy-night"
}
return UIImage(named: imageName)
}
code: struct CurrentWeather
let tempature: Int?
let humidity: Int?
let precipProbability: Int?
let summary: String?
var icon: UIImage? = UIImage(named: "default")
init(weatherDictionary: [String: AnyObject]) {
tempature = weatherDictionary["temperature"] as? Int
if let humidityFloat = weatherDictionary["humidity"] as? Double {
humidity = Int(humidityFloat * 100)
} else {
humidity = nil
}
if let precipFloat = weatherDictionary["precipProbability"] as? Double {
precipProbability = Int(precipFloat * 100)
} else {
precipProbability = nil
}
summary = weatherDictionary["summary"] as? String
if let iconString = weatherDictionary["icon"] as? String,
let weatherIcon: Icon = Icon(rawValue: iconString){
icon = weatherIcon.toImage()
}
}
help please...
1 Answer
Konrad Pilch
2,435 PointsHave you tried debugging your code with the xcode complier?
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsFew things you can check:
*Make sure the image names in the Assets.xcassets folder match the ones listed above.
*Try changing the weather temp manually to view the change.