[Accepted] SE-0194: Derived Collection of Enum Cases

The review of SE-0194 has ended. The proposal is accepted with revisions. The specific changes to the proposal as reviewed are:

  • @objc enums defined in Swift will receive automatic synthesis of the list of all cases. There is no technical basis for limiting synthesis to non-@objc enums. Note that this change does not affect enums defined in (Objective-)C: Swift will (still) not synthesize the list of all cases for imported enums.

  • Unavailable cases will not be listed, because values of an unavailable case cannot exist in a well-typed Swift program (in breaks the availability model).

  • Automatic synthesis is only provided when the conformance is stated on the enum definition (not an extension), following the precedent set by Codable (SE-0167) and Equatable/Hashable synthesis (SE-0185).

  • The protocol, associated type, and property are named CaseIterable, AllCases, and allCases, respectively. The core team felt that these names reflect the primary use case of this protocol, promoting better clarity for most code that iterates over all of the cases. We chose Iterable over Enumerable because Enumerable has some incorrect connotations (e.g., the enumerated() method).

Thank you to the proposal authors and implementer, and everyone who participated in the review!



Quick question: what is the type of the synthesized AllCases? In particular, will it be a RandomAccessCollection?