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 (Retired) Data Modeling With Structures Setting Icon Images

Marcus Davajon
Marcus Davajon
6,882 Points

Errors occurring in switch statement

I've triple checked and my code matches the video.

''swift

func weatherIconFromString(stringIcon: String) -> UIImage
{
    var imageName = String

    switch stringIcon {
    case "clear-day":
        imageName = "clear-day"
    case "clear-night":
        imageName = "clear-night"
    case "rain":
        imageName = "rain"
    case "snow":
        imageName = "snow"
    case "sleet":
        imageName = "sleet"
    case "wind":
        imageName = "wind"
    case "fog":
        imageName = "fog"
    case "cloudy":
        imageName = "cloudy"
    case "partly-cloudy-day":
        imageName = "partly-cloudy"
    case "partly-cloudy-night":
        imageName = "cloudy-night"
    default:
        imageName = "default"
    }

    var iconImage = UIImage(named: imageName)
    return iconImage
}

''

On the var imageName, error = Expected member name or constructor after type name.

Inside the switch statement,10 errors = Type 'String.Type' does not conform to protocol 'StringLiteralConverible'

Please help!!

2 Answers

var imageName: String

not var imageName = String

func weatherIconFromString(stringIcon: String) -> UIImage {
     var imageName: String
Marcus Davajon
Marcus Davajon
6,882 Points

I can't believe I overlooked that over 3 times! Thank you, Kyle! It works now :)