Skip to content

Instantly share code, notes, and snippets.

@grigorye
Created August 6, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grigorye/fa4fce6f0ca63cfb97b3c48448a98239 to your computer and use it in GitHub Desktop.
Save grigorye/fa4fce6f0ca63cfb97b3c48448a98239 to your computer and use it in GitHub Desktop.
protocol MyProtocol {
func methodA()
func methodB()
}
extension MyProtocol {
func methodA() {
print("Default methodA")
}
func methodB() {
methodA()
}
}
// Test 1
protocol BaseProtocol: MyProtocol {
}
protocol SubProtocol: BaseProtocol {
}
extension SubProtocol {
func methodA() {
print("SubProtocol methodA")
}
}
class SubClass: SubProtocol {}
let object1 = SubClass()
object1.methodB()
//
// Test 2
class JustClass: MyProtocol {
func methodA() {
print("JustClass methodA")
}
}
let object2 = JustClass()
object2.methodB()
//
// Output
// SubProtocol methodA
// JustClass methodA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment