On Wed, May 10, 2017 at 8:52 PM, Saagar Jha via swift-evolution < swift-evolution@swift.org> wrote:
> I use a enum (with a Int raw value) for sections in a table view, so > whenever the table view asks for the number of rows I pass in the number of > cases. Currently, I’m doing something like this: > > enum Sections: Int { > case section1: 0 > case section2 > case section3 > case _count > } > > Obviously, this cases issues in switch statements since I need to handle > the _count case with an assertion, but other than that it works rather well. > Yes, it is useful for Table Views, and for pets projects I have done it, at the expense of handling that case due to exhaustive switches. However as Brent stated, it does not fit well into Swift 4 at this late stage, so maybe if better introspection is introduced in Swift 5 it will fit better. Just to be clear, if the proposal that Brent stated gets accepted you could do something like this: let count = Sections.allCases.count And you won't have to put that assert never again. -- Víctor Pimentel
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution