Avatar
protocol MagicProtocol { associatedtype AT1; func getAT1Value() -> AT1 } extension MagicProtocol { func getAT1Value() -> Array<Int> { return [1, 2, 3] } } extension MagicProtocol where AT1 == String { func getAT1Value() -> AT1 { return "AT1 is String" } } extension MagicProtocol where AT1 == Int { func getAT1Value() -> AT1 { return 32 } } struct MagicDog : MagicProtocol {} let dog = MagicDog().getAT1Value() // [1, 2, 3] まともだ