class Animal { } // gyb extension Animal { var switcher: AnimalTypeSwitcher { switch self { case let cat as Cat: return .cat(cat) case let dog as Dog: return .dog(dog) default: fatalError("invalid") } } }