Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created February 15, 2016 05:24
Show Gist options
  • Select an option

  • Save niwatako/74cf22f76f364867607e to your computer and use it in GitHub Desktop.

Select an option

Save niwatako/74cf22f76f364867607e to your computer and use it in GitHub Desktop.
extension で親子別々の実装にしたい: Playgroundでは行けた( `・ω´・) #CodePiece
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