You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CaseIterable lets users access all states of a type as a Collection. Since Bool only has two states, this should be easy to do. Surprisingly, it hasn't been done yet (as of this writing). Not having this prevents automatic conformance with any type that would otherwise conform except that it has at least one stored Bool property.
The text was updated successfully, but these errors were encountered:
Because in this case, the problem would be that only string, integer, or floating-point literals are supported as raw type on enums.
Which came up to me as a bit surprising. So the solution was to maybe support BooleanLiteral as RawType as well?
We can actually work around this by making bool conforms to `ExpressibleByIntegerLiteral`
extensionBool: ExpressibleByIntegerLiteral {
publictypealiasIntegerLiteralType = Intpublicinit(integerLiteralvalue: Int) {
self = value != 0
}
}
enumE: Bool, CaseIterable { //Now this compiles and synthetizes the CaseInterable and RawRepresentablecasea = truecaseb = false
}
_ = E.allCases// [E.a, E.b]
To me, this would be solved by having boolean literal acceptable as raw type.
But, I'm definitely not sure if this is what you meant by having bool conform to `CaseIterable`... if it's not that, can you share an example of a use case?
That would make it easier to understand the intention here 🙂
extensionBool:CaseIterable{publicstructAllCases:RandomAccessCollection{@inlinablepublicvarstartIndex:Int{return0}@inlinablepublicvarendIndex:Int{return2}@inlinablepublic subscript(position:Int)->Bool{
switch position {case0:return false
case1:return true
default:preconditionFailure("Out of range subscript position")}}@usableFromInlineinit(){}}@inlinablepublicstaticvarallCases:AllCases{returnAllCases()}}
Additional Detail from JIRA
md5: 96af0f9565de3fb27856bc0b75534452
Issue Description:
The
CaseIterable
lets users access all states of a type as aCollection
. SinceBool
only has two states, this should be easy to do. Surprisingly, it hasn't been done yet (as of this writing). Not having this prevents automatic conformance with any type that would otherwise conform except that it has at least one storedBool
property.The text was updated successfully, but these errors were encountered: