Skip to content

Instantly share code, notes, and snippets.

@yimajo
Last active March 30, 2019 06:52
Show Gist options
  • Save yimajo/16d1e1ce199dda4694b605b584bbe609 to your computer and use it in GitHub Desktop.
Save yimajo/16d1e1ce199dda4694b605b584bbe609 to your computer and use it in GitHub Desktop.
Swift5からprotocolでclassをinheritできるようになった?
class Hoge {}
// Swift 5から
protocol ComponentA: Hoge {
func name() -> String
}
// Swift 4でも同じようなことはできた
protocol ComponentB where Self: Hoge {
func name() -> String
}
class Piyo: Hoge, ComponentA, /*ComponentB*/ {
func name() -> String {
return "piyo"
}
}
print(Piyo().name())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment