1

Compiling following code:

protocol Foo {
    associatedtype Element
}

protocol IntFoo: Foo where Element == Int {
}

struct A: IntFoo {
}

let intFoo: IntFoo = A()

produces error message: Protocol 'IntFoo' can only be used as a generic constraint because it has Self or associated type requirements.

Didn't I just specify an associated type requirement or am I doing it wrong?

  • Have a look at https://stackoverflow.com/questions/36348061/protocol-can-only-be-used-as-a-generic-constraint-because-it-has-self-or-associa – Papershine Jul 13 '18 at 12:02

0 Answers0