Is this a good idea? protocol IdentifiableHashable: Hashable, Identifiable { }

While I don't really have any useful opinions on the main point you raised in your post, I can answer this question. :slight_smile:

The answer is yes. A single inheritance clause with a protocol composition is equivalent to multiple inheritance clause entries where each one is a single protocol.

There's also an interesting useless bit of trivia here. Could we hypothetically deprecate the , syntax for writing out multiple inheritance clause entries and always have a single one which might be a protocol composition? The answer is almost, but not quite, unfortunately. The one exception is that enums can declare a RawRepresentable conformance by "inheriting" from their raw type, eg

enum Foo : Int, SomeProtocol {
  case a = 1
}

Since Int is neither a protocol nor a class, it cannot appear in a protocol composition, so it would not be valid to write enum Foo : Int & SomeProtocol.

11 Likes