Swift switch statement for matching substrings of a String

I had a similar problem today and realized this question hasn’t been updated since Swift 1! Here’s how I solved it in Swift 4:

switch self.descriptionWeather.description {
case let str where str.contains("Clear"):
    print("clear")
case let str where str.contains("rain"):
    print("rain")
case let str where str.contains("broken clouds"):
    print("broken clouds")
default:
    break
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)