Does using enum with associated value in Swift violate Liskov Substitution Principle?
问题 enum WeatherType { case cloudy(coverage: Int) case sunny case windy } I just saw this in a Swift tutorial and I can't believe they allow you to do that. Now, whenever I switch on that enum, I gotta create a special case for cloudy ! 回答1: You don't "gotta" do anything. If you don't care what the coverage is, don't ask what the coverage is. If you don't care if it's cloudy, don't ask if it's cloudy. There is nothing special about the way you write a switch for a case that has an associated