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 12,851 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