Swift 101 - Protocols - Index of interesting topics

I have recently come across an interesting discussion on protocols in which @Nickolas_Pohilets uses the phrase lookup in the conformance tables. Then, @Andropov proposes an elegant counter example.

After reading that discussion, I thought it would be useful to have a central repository-like index of interesting discussions on protocols.

So here is my list, which I intend to grow as I encounter new ones.

Make Default Implementations Safer

How can we make default implementations safer?

Covariant Self on Protocols and Classes

Why Is Covariant Self more flexible on protocols than classes?

Summary

Lightweight Same-Type Requirements for Primary Associated Types

SE-0346: Lightweight same-type requirements for primary associated types

Infinitely Recursive Associated Types

Limitations with infinitely-recursive associated types

Summary

Protocol Where Clause vs Protocol Inheritance

Protocol with a where clause vs protocol inheritance

Associated Type Inference

Recent improvements to associated type inference

Summary

Synchronous Functions Can Satisfy Async Protocol Requirements

Protocol with async function allows implementation without async?

See Also SE-0296 - Protocol conformance

A protocol requirement can be declared as async. Such a requirement can be satisfied by an async or synchronous function. However, a synchronous function requirement cannot be satisfied by an async function. For example:

Summary
protocol Asynchronous {
  func f() async
}

protocol Synchronous {
  func g()
}

struct S1: Asynchronous {
  func f() async { } // okay, exactly matches
}

struct S2: Asynchronous {
  func f() { } // okay, synchronous function satisfying async requirement
}

struct S3: Synchronous {
  func g() { } // okay, exactly matches
}

struct S4: Synchronous {
  func g() async { } // error: cannot satisfy synchronous requirement with an async function
}

This behavior follows the subtyping/implicit conversion rule for asynchronous functions, as is precedented by the behavior of throws.

Why Isn't My Implementation Called?

Summary

Cases Where Non-Exact Matches Are Accepted

Summary
Summary

Why Can't any FixedWidthInteger Conform to FixedWidthInteger?

Summary
5 Likes