Avatar
omochimetaru 8/10/2017 4:36 AM
class Animal {} class Cat : Animal {} var animalArray: [Animal] = Array<Cat>([Cat(), Cat()]) switch animalArray as Any { case let catArray as [Cat]: print(catArray) break default: print("default") break } 本当だ、いけますね (edited)
4:36 AM
class Animal {} class Cat : Animal {} class Dog : Animal {} var animalArray: [Animal] = Array<Cat>([Cat(), Cat()]) animalArray.append(Dog()) switch animalArray as Any { case let catArray as [Cat]: print(catArray) break default: print("default") break } こう書き換えたら default って出力に変わった。やっぱり全部見ている。