Search code examples
iosswiftprotocolsany

How to use 'any' with multiple protocol types?


I had the following:

protocol MyProtocol: CustomStringConvertible, CaseIterable {
    ...
}

...

var objects: [any MyProtocol]

Now I want to get rid of MyProtocol.

Probably a silly question, but how do I then define my objects property? This:

var objects: [any CustomStringConvertible, CaseIterable]

of course doesn't work.


Solution

  • [any CustomStringConvertible & CaseIterable]