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

iOS Build a Weather App with Swift Adding Weather Icons Streamlining Our Icon Enum

Todd Walker
Todd Walker
1,611 Points

Streamlining Our Icon Enum: threw an error at the end of the video.

Hi everyone, I seemed to follow along in the video just fine until the end and I've thrown an error that says: "!Missing return in a function expected to return "UIImage?" (line 54).

Here's the code:

import UIKit import Foundation

enum Icon: String { case ClearDay = "clear-day" case ClearNight = "clear-night" case Rain = "rain" case Snow = "snow" case Sleet = "sleet" case Wind = "wind" case Fog = "fog" case Cloudy = "cloudy" case PartlyCloudyDay = "partly-cloudy-day" case ParlyCloudyNight = "partly-cloudy-night"

func toImage() -> UIImage? {
    var imageName: String

    switch self {
    case .ClearDay:
        imageName = "clear-day.png"
    case .ClearNight:
        imageName = "clear-night.png"
    case .Rain:
        imageName = "rain.png"
    case .Snow:
        imageName = "snow.png"
    case .Sleet:
        imageName = "sleet.png"
    case .Wind:
        imageName = "wind.png"
    case .Fog:
        imageName = "fog.png"
    case .Cloudy:
        imageName = "cloudy.png"
    case .PartlyCloudyDay:
        imageName = "cloudy-day.png"
    case .ParlyCloudyNight:
        imageName = "cloudy-day.png"

    return UIImage(named: imageName)


    }

}

2 Answers

Maybe removing the return line out of the brackets will help?

Try this:

    func toImage() -> UIImage? {      
        var imageName: String

            switch self {

            case .ClearDay:
                imageName = "clear-day.png"
            case .ClearNight:
                imageName = "clear-night.png"
            case .Rain:
                imageName = "rain.png"
            case .Snow:
                imageName = "snow.png"
            case .Sleet:
                imageName = "sleet.png"
            case .Wind:
                imageName = "wind.png"
            case .Fog:
                imageName = "fog.png"
            case .Cloudy:
                imageName = "cloudy.png"
            case .PartlyCloudyDay:
                imageName = "cloudy-day.png"
            case .PartlyCloudyNight:
                imageName = "cloudy-night.png"
            default:  
                imageName = "default.png"      
            }                                                              

        return UIImage(named: imageName)  
    }
}

Same Todd Walker i have the same issues as well