enum scope

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 8 02:15:14 PDT 2014


On 2014-06-08 01:58, deadalnix wrote:

> I'm not sure why it is usually done that way in D binding. This is
> idiotic (and all Deimos exhibit this).
>
> enum UITableViewRowAnimation {
>      Fade,
>      Right,
>      Left,
>      Top,
>      Bottom,
>      None,
>      Middle,
>      Automatic = 100
> }
>
> Here you go. You gain type safety (well kind of) and you don't need to
> increase verbosity. You can even use the with statement for code that
> use the enum intensively, for instance :
>
> final switch(myvar) with(UITableViewRowAnimation) {
>      case Fade:
>         // Do fading...
>      case Right:
>         // That's right...
>      case Left:
>         // That's not right..
>      // And so on...
> }
>
> That is superior to the idiotic C copy pasta in all aspects.

In Swift you don't have to specify the full enum name if the compiler 
can infer that it's an value of specific enum that is needed:

void foo (UITableViewRowAnimation);

foo(Fade);

Actually in Swift you would append a dot to the enum value:

foo(.Fade);

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list