Just curious: why "error: raw type 'Int' must appear first in the enum inheritance clause"

enum Foo: CaseIterable, Int {   // error: raw type 'Int' must appear first in the enum inheritance clause
    case blah
}

why does Swift insist on one ordering?

(Non-protocol) types are listed before protocols in inheritance clauses in Swift. It's the same rule for subclassing:

class A { }
class B: Hashable, A { } // error: superclass 'A' must appear first in the inheritance clause

This is helpful for readers to see at a glance if there is any inheritance from another concrete type by reading at most one position after the colon. If these could be anywhere in the inheritance clause, a reader would have to read (and possibly look up) arbitrarily many names to determine if there is such a relationship.

9 Likes
Terms of Service

Privacy Policy

Cookie Policy