Protocol conformance for protocols with `var myVar: MyType { get }`

No it shouldn't, the compiler is basically only allowing you to write code exactly how you told it to with your protocol design. In the first original example you explicitly said that you want the conforming type to have a get-only property with a Kraken existential (a box type created by the compiler to store any type that also conforms to the Kraken protocol). Therefore the compiler awaits that you use Kraken and not a concrete type.
On the other hand if you use an associated type, the compiler awaits that you tell it which concrete type you want to associated with the conformance of the protocol.


OPTIONAL:

If you're curious to learn more, there is a huge discussion on how we eventually want to improve some of the generics UI in swift which also covers some of the 'existential' and 'opaque result type' landscape:

In short we have:

  • Kraken as a protocol
  • Kraken as a protocol type - existential, which eventually might become any Kraken
  • there is also potentially a some Kraken which is the opaque result type (also called reversed generics by others) that allows you to hide the concrete type for your user, but not from the compiler so that you can use that type in generic context.

There is a lot more to cover but I don't want overwhelm you with all that information. I do recommend you to read the official Swift book if you haven't already, it definitely covers the most essential part of these things.

1 Like