Created
February 15, 2016 05:23
-
-
Save niwatako/fa5a95c41f45089340a0 to your computer and use it in GitHub Desktop.
extension で親子別々の実装にしたい: Playgroundでは行けた( `・ω´・) 実際のコードでB().name がAになってしまうのだけど、型の認識のされ方の問題? #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol SomeProtocol { | |
| var name: String { get } | |
| } | |
| class A {} | |
| class B: A {} | |
| extension A: SomeProtocol {} | |
| extension SomeProtocol where Self: A { | |
| var name: String { return "My name is A" } | |
| } | |
| extension SomeProtocol where Self: B { | |
| var name: String { return "My name is B" } | |
| } | |
| A().name // My name is A | |
| B().name // My name is B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment