Last active
March 21, 2021 02:47
-
-
Save msbit/9b6538855d00b473d90f7882ea78d031 to your computer and use it in GitHub Desktop.
Swift inheritance hierarchy protocol conformance in generic context
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 Consumer { | |
static func consume(_ instance: Self) | |
} | |
class Base: Consumer { | |
class func consume(_ instance: Base) { print("Base.consume(_:)") } | |
} | |
class Derived: Base { | |
class func consume(_ instance: Derived) { print("Derived.consume(_:)") } | |
} | |
class Generic <C: Consumer> { | |
class func consume(_ instance: C) { C.consume(instance) } | |
} | |
Generic<Base>.consume(Base()) | |
Generic<Base>.consume(Derived()) | |
Generic<Derived>.consume(Derived()) |
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
Base.consume(_:) | |
Base.consume(_:) | |
Base.consume(_:) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment