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 trialmitulhpatel
2,678 PointsCan't get around unwrapped value for icons
var iconImage = UIImage(named: imageName)
return iconImage
Throws me an error at return iconImage that you need to unwrap it although that is not the case in the video. I can unwrap the value by using return iconImage! but then it returns nil value. Everything else works just fine in later on videos. It is returning the correct string from dictionary for stringIcon.
3 Answers
mitulhpatel
2,678 PointsThanks but turns out data for icon from forecast.io were not coming up right which were causing the issue but I have fixed that so it is working now. Something to note is that in the video value is not unwrapped for return iconImage which will still throw an error so just add ! after it.
Edited on 11/19/2014 I was wrong in saying that forcast.io were not coming up right. They were coming up right but just returning a nil value specifically for partly-cloudy images which happens to be all the time in area I chose so it was a difficult to figure out the problem but there were no images for partly-cloudy in Xcode.
Johannes Böhm
5,957 PointsI had the same issues for unwrapping iconName and I added "!" at the end of the return statement. But then after that I got following error showing up in the console:
"fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) "
any ideas on that?
Dan Merchant
Courses Plus Student 22,186 Pointshave you tried:
if let iconImage = UIImage(name: imageName) { return iconImage } else { .... handle nil condition }
Ed Williams
2,969 PointsEd Williams
2,969 PointsI had this same issue and added "!" to resolve it too. When you say "data for icon from forecast.io were not coming up right" please can you explain and give specific examples? Thanks!