Created
August 6, 2018 11:13
-
-
Save grigorye/fa4fce6f0ca63cfb97b3c48448a98239 to your computer and use it in GitHub Desktop.
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 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