Swift enum with no static properties conforms to a protocol which requires a static property
Asked Answered
A

0

0

Accidentally stumbled upon an interesting post.

In a nutshell:

protocol Unknownable {
    static var unknown: Self { get }
}

enum Type: Unknownable {
    case text
    case image
    case document
    case unknown
}

So why does the conformence compiles?

Apologize answered 24/4 at 6:4 Comment(2)
It is unclear what kind of answer you are looking for. Would you not want this code to compile instead? It is useful to allow enum cases to witness static protocol requirements, and implementing it is not complicated. Your previous post also has the same issue, but at least there is something useful that I can put in an answer. See also: meta.https://mcmap.net/q/271327/-important-ui-features-that-are-often-left-out-closed – Veronicaveronika
>> "Would you not want this code to compile instead?" No-no, I wouldn't mind that πŸ˜… Just was very surprised πŸ™‚ Looks like it's just a language feature I didn't know about πŸ™ƒ @Veronicaveronika – Apologize

© 2022 - 2024 β€” McMap. All rights reserved.