On 3 Nov 2016, at 8:37 PM, Erica Sadun via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:
> private enum StringEnum: String { case one, two, three } > public init(strings: [String]) { > var set = MyOptionSet() > strings.flatMap({ StringEnum(rawValue: $0) }) > .flatMap({ MyOptionSet(rawValue: 1 << $0.hashValue) }) > .forEach { set.insert($0) } > _rawValue = set.rawValue > } I’m curious about relying on the hash value of an enum case being its declaration-order index. A sage (http://ericasadun.com/2015/07/12/swift-enumerations-or-how-to-annoy-tom/ <http://ericasadun.com/2015/07/12/swift-enumerations-or-how-to-annoy-tom/>) warns that this is an implementation detail. I haven’t seen anything saying it is API. Has it been resolved? It’s the most plausible implementation, but I’d think code that relies on case order would break silently (likely at widely-separated locations) if a case were inserted or removed. That suggests to me it’s not possible to regularize this behavior. Folkloric API (like SEL ↔︎ char* in ObjC) makes me itch. — F
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users