News for hackers. Stuff that matters.
Re:API design note: Beware of adding an "Other" enum value by mayoff on Sunday March 02, 2025 @05:44PM (#43236061)
Swift allows an enum to be marked `@frozen`, which is an API (and ABI) stability guarantee that the enum will never gain more cases. Apple uses this quite sparingly in their APIs.

Swift also has two versions of a `default` case in switch statements, like you described. It has regular `default` and it has `@unknown default`. The `@unknown default` case is specifically for use with non-frozen enums, and gives a warning if you haven't handled all known cases.

So with `@unknown default`, the compiler tells you if you haven't been exhaustive (vs. the current API), but doesn't complain that your `@unknown default` case is unreachable.

Re:API design note: Beware of adding an "Other" enum value by layer8 on Sunday March 02, 2025 @05:58PM (#43236175)
Ah, thanks, I wasn’t aware of these two “default” variants in Swift.