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

Jhoan Arango
MOD
Jhoan Arango
Treehouse Moderator 13,603 Points

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'

Jhoan Arango
Jhoan Arango
Treehouse Moderator 13,603 Points

Adolfo,

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