Avatar
omochimetaru 8/2/2018 7:28 AM
protocol AnimalProtocol {} extension AnimalProtocol { mutating func replace(with obj: Self) { self = obj } } struct Cat: AnimalProtocol {} struct Dog: AnimalProtocol {} var cat: AnimalProtocol = Cat() cat.replace(with: Dog()) print(type(of: cat)) /* error: iOSGround.playground:6:1: error: member 'replace' cannot be used on value of protocol type 'AnimalProtocol'; use a generic constraint instead cat.replace(with: Dog()) ^~~ ~~~~~~~ */
7:28 AM
セーフだった。