Is it possible to have a protocol that specializes a generic protocol? I want something like this:
protocol Protocol: RawRepresentable {
typealias RawValue = Int
...
}
This does compile, but when I try to access the init
or rawValue
from a Protocol instance, its type is RawValue
instead of Int
.
In Swift 4, you can add constraints to your protocol:
And now all methods defined on MyProtocol will have an Int rawValue. For example:
Types that adopt RawRepresentable but whose RawValue is not Int can not adopt your constrained protocol: