Swift switch statement for matching substrings of a String

前端 未结 7 1557
时光说笑
时光说笑 2021-01-01 15:55

Im trying to ask for some values from a variable. The variable is going to have the description of the weather and i want to ask for specific words in order to show differen

相关标签:
7条回答
  • 2021-01-01 16:53

    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
    }
    
    0 讨论(0)
提交回复
热议问题