无法获取要显示的图标

时间:2015-08-18 23:32:35

标签: ios swift enums uiimage uikit

我无法显示我的图标,我在网上收到错误:返回UIImage(名称:imageName)

错误说:在预期返回“UIImage?”的函数中缺少返回

如果有人能帮助我摆脱这个恼人的错误,请提前谢谢。

import Foundation
    import UIKit

    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 PartlyCloudyNight = "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 .PartlyCloudyNight:
                imageName = "cloudy-night.png"

                return UIImage(named: imageName)
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

您的退货声明是在您的转换的.PartlyCloudyNight情况下。你需要把它移到开关外面。