if else 让这个代码没法读了
小林老师那个 if else 让这个代码没法读了,用 switch case 的 Range Matching 是不是比较合适些?
小林老师那个 if else 让这个代码没法读了,用 switch case 的 Range Matching 是不是比较合适些?
2015-04-21
switch condition {
case 0..<300:
if isNight {
imageView.image = UIImage(named: "tstrom1_night")
} else {
imageView.image = UIImage(named: "tstrom1")
}
case 300..<500:
imageView.image = UIImage(named: "rain")
case 500..<600:
imageView.image = UIImage(named: "shower_rain")
case 600..<700:
imageView.image = UIImage(named: "snow4")
case 700..<771:
if isNight {
imageView.image = UIImage(named: "fog_night")
} else {
imageView.image = UIImage(named: "fog")
}
case 771..<800:
imageView.image = UIImage(named: "tstrom3")
case 800:
if isNight {
imageView.image = UIImage(named: "sunny_night")
} else {
imageView.image = UIImage(named: "sunny")
}
case 801..<804:
if isNight {
imageView.image = UIImage(named: "cloudy_night")
} else {
imageView.image = UIImage(named: "cloudy")
}
case 804:
imageView.image = UIImage(named: "overcast")
case 900..<903:
fallthrough
case 905..<1000:
imageView.image = UIImage(named: "tstrom3")
case 903:
imageView.image = UIImage(named: "snow5")
case 904:
imageView.image = UIImage(named: "sunny")
default:
imageView.image = UIImage(named: "dunno")
}
举报