Swift. UILabel text alignment
These are now enums. You can do: label.textAlignment = NSTextAlignment.center; Or, for shorthand: label.textAlignment = .center; Swift 3 label.textAlignment = .center
These are now enums. You can do: label.textAlignment = NSTextAlignment.center; Or, for shorthand: label.textAlignment = .center; Swift 3 label.textAlignment = .center
int idx = 2; print(ThemeColor.values[idx]); should give you ThemeColor.blue
I also had this problem. Easy way to get around it: add a + sign before your variable in the switch, i.e. switch (+editMode) { case EditMode.Delete: … break; case EditMode.Edit: … break; default: … break; }
This is the JavaScript output of that enum: var MyEnum; (function (MyEnum) { MyEnum[MyEnum[“First”] = 0] = “First”; MyEnum[MyEnum[“Second”] = 1] = “Second”; MyEnum[MyEnum[“Third”] = 2] = “Third”; })(MyEnum || (MyEnum = {})); Which is an object like this: { “0”: “First”, “1”: “Second”, “2”: “Third”, “First”: 0, “Second”: 1, “Third”: 2 } Enum Members … Read more
Just like with any other class, you can define a class object in an enum class: enum class CircleType { FIRST, SECOND, THIRD; companion object { fun random(): CircleType = FIRST // http://dilbert.com/strip/2001-10-25 } } Then you’ll be able to call this function as CircleType.random(). EDIT: Note the commas between the enum constant entries, and … Read more
Beginning 1.8, you can use enums like this: enum Fruit { apple, banana } main() { var a = Fruit.apple; switch (a) { case Fruit.apple: print(‘it is an apple’); break; } // get all the values of the enums for (List<Fruit> value in Fruit.values) { print(value); } // get the second value print(Fruit.values[1]); } The … Read more
You can either have a class that is separate to the Enum and use it to get things you want, or you can merge a namespace into the Enum and get it all in what looks like the same place. Mode Utility Class So this isn’t exactly what you are after, but this allows you … Read more
You can use the strum crate to easily iterate through the values of an enum. use strum::IntoEnumIterator; // 0.17.1 use strum_macros::EnumIter; // 0.17.1 #[derive(Debug, EnumIter)] enum Direction { NORTH, SOUTH, EAST, WEST, } fn main() { for direction in Direction::iter() { println!(“{:?}”, direction); } } Output: NORTH SOUTH EAST WEST
There are four different aspects to enums in TypeScript you need to be aware of. First, some definitions: “lookup object” If you write this enum: enum Foo { X, Y } TypeScript will emit the following object: var Foo; (function (Foo) { Foo[Foo[“X”] = 0] = “X”; Foo[Foo[“Y”] = 1] = “Y”; })(Foo || (Foo … Read more
Dart 2.7 comes with new feature called Extension methods. Now you can write your own methods for Enum as simple as that! enum Day { monday, tuesday } extension ParseToString on Day { String toShortString() { return this.toString().split(‘.’).last; } } main() { Day monday = Day.monday; print(monday.toShortString()); //prints ‘monday’ }