Alastair
Alastair

Reputation: 6114

Swift extensions: adding where AND protocol adherence

I can do this:

extension Dictionary : MyProtocol {}

and I can do this:

extension Dictionary where Key: String, Value: Int {}

but I can't do this:

extension Dictionary where Key: String, Value: Int : MyProtocol {}

or this:

extension Dictionary : MyProtocol where Key: String, Value: Int {}

What's the correct way to format that to allow me to specify types and also specify adherence to a protocol?

Upvotes: 0

Views: 79

Answers (2)

Alastair
Alastair

Reputation: 6114

OK, I'm an idiot. Just realised the last example gives this error:

Extension of type 'Dictionary' with constraints cannot have an inheritance clause

So presumably it simply isn't possible yet.

Upvotes: 0

Related Questions