Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Weather App Modeling Forecast Data Icon Images

Joey Liu
Joey Liu
3,982 Points

my clear-day doesn't turn into image

var iconImage: UIImage {
        switch icon {
        case "clear-day": return clear-day
}

so my clear-day doesn't pop up in the list for me to select like the video revealed that I cannot turn it into images in Asset.xcasset. What is the possible problem? Do I have to use #imageLiteral(resourceName: ) ?

1 Answer

Hello,

So this computed property should return a "UIImage", and you are just returning "clear-day" string. To fix this, you have to use the UIImage initializer "named". This will make an image, and then you will return it.

var iconImage: UIImage {
        switch icon {
        case "clear-day": return UIImage(named: "clear-day")
        default: break
        }
}

Hope this help

Adolfo Obregon
Adolfo Obregon
10,156 Points

Hi, i had the same issue but now im gettin the following error : Value of optional type 'UIImage?' must be unwrapped to a value of type 'UIImage'

Adolfo,

I am sorry for the late response, are you able to show me your code?