Enum case count


(Joao Nunes) #1

Hi,

I have one proposal for the language to add a property to enums with the total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

···

Sent from my iPhone


(Jacob Bandes-Storch) #2

The pull request is waiting to be merged.

https://github.com/apple/swift-evolution/pull/114

···

On Thu, Feb 18, 2016 at 10:08 AM, Ross O'Brien via swift-evolution < swift-evolution@swift.org> wrote:

João,

your proposal has been proposed before, but I don't think it's been
formally submitted for review yet:

https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org> > wrote:

Hi,

I have one proposal for the language to add a property to enums with the
total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #3

I'd really like to see the count / collection thing happen.

-- E

···

On Feb 18, 2016, at 11:08 AM, Ross O'Brien via swift-evolution <swift-evolution@swift.org> wrote:

João,

your proposal has been proposed before, but I don't think it's been formally submitted for review yet:
https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Hi,

I have one proposal for the language to add a property to enums with the total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Ross O'Brien) #4

João,

your proposal has been proposed before, but I don't think it's been
formally submitted for review yet:
https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

···

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org> wrote:

Hi,

I have one proposal for the language to add a property to enums with the
total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Joao Nunes) #5

Thanks Ross.

In that case ignore my email.

João Nunes

···

On 18 Feb 2016, at 20:08, Ross O'Brien <narrativium+swift@gmail.com> wrote:

João,

your proposal has been proposed before, but I don't think it's been formally submitted for review yet:
https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Hi,

I have one proposal for the language to add a property to enums with the total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


(Joao Nunes) #6

Richard,

Why not the following?

enum Foo {
   case Bar(String)
   case Baz(Int)
}

let cases: [String: Any] = Foo.allCases
print(cases)
// [.Bar(String), .Baz(Int)]

João Nunes

···

On 18 Feb 2016, at 20:22, Erica Sadun <erica@ericasadun.com> wrote:

I'd really like to see the count / collection thing happen.

-- E

On Feb 18, 2016, at 11:08 AM, Ross O'Brien via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

João,

your proposal has been proposed before, but I don't think it's been formally submitted for review yet:
https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Hi,

I have one proposal for the language to add a property to enums with the total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution


#7

Because returning a usable function reference is more useful than just a string describing the argument types, at least for most common use cases.

···

--
Richard

On Feb 18, 2016, at 10:33 AM, Joao Nunes via swift-evolution <swift-evolution@swift.org> wrote:

Richard,

Why not the following?

enum Foo {
   case Bar(String)
   case Baz(Int)
}

let cases: [String: Any] = Foo.allCases
print(cases)
// [.Bar(String), .Baz(Int)]

João Nunes

On 18 Feb 2016, at 20:22, Erica Sadun <erica@ericasadun.com> wrote:

I'd really like to see the count / collection thing happen.

-- E

On Feb 18, 2016, at 11:08 AM, Ross O'Brien via swift-evolution <swift-evolution@swift.org> wrote:

João,

your proposal has been proposed before, but I don't think it's been formally submitted for review yet:
https://github.com/jtbandes/swift-evolution/blob/977a9923fd551491623b6bfd398d5859488fe1ae/proposals/0000-derived-collection-of-enum-cases.md

On Thu, Feb 18, 2016 at 5:57 PM, João Nunes <swift-evolution@swift.org> wrote:
Hi,

I have one proposal for the language to add a property to enums with the total number of cases.

Example:

enum Section {
case Tag
case Article
}

let cases = Section.caseCount

This would be extremely useful when using enums for tableviews.

What do you think?

João Nunes

Sent from my iPhone
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution