Created
August 6, 2018 11:39
-
-
Save grigorye/27e0f6e4f50a7650768ccd1761f6587a to your computer and use it in GitHub Desktop.
This file contains 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() | |
} | |
class MyProtocolDefaults { | |
func methodA() { | |
print("Default methodA") | |
} | |
func methodB() { | |
methodA() | |
} | |
} | |
// Test 1 | |
class BaseClass: MyProtocolDefaults, MyProtocol { | |
} | |
class SubClass: BaseClass { | |
override func methodA() { | |
print("SubClass methodA") | |
} | |
} | |
let object1 = SubClass() | |
object1.methodB() | |
// | |
// Test 2 | |
class JustClass: MyProtocolDefaults, MyProtocol { | |
override func methodA() { | |
print("JustClass methodA") | |
} | |
} | |
let object2 = JustClass() | |
object2.methodB() | |
// | |
// Output | |
// SubClass methodA | |
// JustClass methodA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment