I have the following I want to achieve in Swift:
I have a protocol
protocol IdProtocol {
static var id: Int { get }
}
Now I want each implementor of this potocol to have a different value for id
.
For example:
struct One: IdProtocol {}
struct Two: IdProtocol {}
Here, One
will have id 0 and Two
will have id 1 (or vice versa).
How can I implement this in Swift? I'd like to have this as a protocol extension so that all structs implementing IdProtocol will automatically be assigned an id. This can be done lazily.
I haven't been able to find a solution to this.