Swift switch statement for matching substrings of a String

前端 未结 7 1587
时光说笑
时光说笑 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:45

    Swift language has two kinds of OR operators - the bitwise ones | (single vertical line), and the logical ones || (double vertical line). In this situation you need a logical OR:

    if self.descriptionWeather.description.rangeOfString("Clear") != nil || self.descriptionWeather.description.rangeOfString("clear") != nil {
        self.imageWeather.image = self.soleadoImage
    }
    

    Unlike Objective-C where you could get away with a bitwise OR in exchange for getting a slightly different run-time semantic, Swift requires a logical OR in the expression above.

提交回复
热议问题