Skip to content

Instantly share code, notes, and snippets.

// Given a `protocol P: AnyObject { ... }`, it would be useful to be able to express
// a heterogeneous set of weak references to instances of classes that fulfill the given protocol.
// This would allow to ergonomically maintain bi-directional many-to-one object relations,
// such as e.g. in cases where various `Thing`s need to serve as delegates of a central `ThingManager`,
// without being owned by it.
// In order to implement such a collection, one would need to be able to write code that is generic
// over a "protocol parameter," so to speak, instead of a type parameter. Swift's generics system
// doesn't currently have such a concept.
// I haven't given much thought to how such a feature should be represented syntactically.
// It might be worth differentiating generic type vs. protocol parameters in a similar manner to