enumeration

How to get the name of enumeration value in Swift?

本秂侑毒 提交于 2019-12-17 10:32:25
问题 If I have an enumeration with raw Integer values: enum City: Int { case Melbourne = 1, Chelyabinsk, Bursa } let city = City.Melbourne How can I convert a city value to a string Melbourne ? Is this kind of a type name introspection available in the language? Something like (this code will not work): println("Your city is \(city.magicFunction)") > Your city is Melbourne 回答1: As of Xcode 7 beta 5 (Swift version 2) you can now print type names and enum cases by default using print(_:) , or

foreach vs someList.ForEach(){}

时光总嘲笑我的痴心妄想 提交于 2019-12-17 04:16:05
问题 There are apparently many ways to iterate over a collection. Curious if there are any differences, or why you'd use one way over the other. First type: List<string> someList = <some way to init> foreach(string s in someList) { <process the string> } Other Way: List<string> someList = <some way to init> someList.ForEach(delegate(string s) { <process the string> }); I suppose off the top of my head, that instead of the anonymous delegate I use above, you'd have a reusable delegate you could

The foreach identifier and closures

与世无争的帅哥 提交于 2019-12-16 19:50:10
问题 In the two following snippets, is the first one safe or must you do the second one? By safe I mean is each thread guaranteed to call the method on the Foo from the same loop iteration in which the thread was created? Or must you copy the reference to a new variable "local" to each iteration of the loop? var threads = new List<Thread>(); foreach (Foo f in ListOfFoo) { Thread thread = new Thread(() => f.DoSomething()); threads.Add(thread); thread.Start(); } - var threads = new List<Thread>();

Adding Local Filenames/References To Array In Actionscript

一个人想着一个人 提交于 2019-12-14 04:01:58
问题 how can i cycle thru a local folder to add all (or some) files names and references to that file in an array using actionscript 3.0? var fileArray:Array = new Array(); for (var item:Object in "../myFolder/") { trace(item.name); fileArray.push(item); } something like this? 回答1: You can only access the file system using AIR :/, or by having Flex make an HTTP call to a server-side language like ruby/python/php and having it return that information. Here is an AIR Directory Listing Example (you

Python — how to force enumerate to start at 1 — or workaround?

与世无争的帅哥 提交于 2019-12-14 01:26:20
问题 I have a simple for loop: for index, (key, value) in enumerate(self.addArgs["khzObj"].nodes.items()): and I want to start a new wx horizontal boxsizer after every 3rd item to create a panel with 3 nodes each and going on for as many as are in nodes. The obvious solution is to do: if index % 3 == 0: add a horizontal spacer but the enumerate starts at 0, so 0 % 3 == 0 and it would start a new row right off the bat. I've tried doing: if index == 0: index = index + 1 but of course that doesn't

c# list and enumerator with properties

社会主义新天地 提交于 2019-12-13 15:57:18
问题 I have the following problem: I have a list and add string items to this list. Then I create an Enumerator out of the list. When I loop through the list with the MoveNext() command it works when I access the enumerator directly. When I use the Enumerator properties to access the enumerator it doesn't work. The MoveNext() command doesn't increment the index. Here is the code I used. Thanks a lot for your help. public class DummyKlasse { public List<string>.Enumerator enumerator; public List

NSMutableArray enumerateObjectsUsingBlock is not synchronous as Apple says

Deadly 提交于 2019-12-13 14:51:28
问题 Is this a bug? I have this lines: [myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"%d", idx); }]; NSLog(@"end"); This should print like this "0" "1" "2" ... "end" but it is printing like "end" "0" "1" "2" ... Apple says enumerateObjectsWithOptions:usingBlock: is synchronous, so "end" should not be printed before the enumeration, right? Can you guys confirm? 回答1: enumerateObjectsUsingBlock: is definitely synchronous. I just ran the same example in CodeRunner:

Design issues and implementing Enumerable.AsEnumerable<FarPoint.Win.Spread.Row>

微笑、不失礼 提交于 2019-12-13 09:35:43
问题 How can i make a datatype return IEnumerable<datatype> if it does not have AsEnumerable() method. For example: FarPointSpread1.ActiveSheet.Rows[e.Row] does not contain AsEnumerable() so i cannot do this FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable() e.Row is the current row in the spread's activesheet and i am expecting to be able to do something like this: IEnumerable<FarPoint.Win.Spread.Row> = FarPointSpread1.ActiveSheet.Rows[e.Row].AsEnumerable(); I want to iterate over all fields

DataGridComboBoxColumn binding to List<Enum>

喜你入骨 提交于 2019-12-13 00:28:58
问题 I want to bind a list of enum values to a 'DataGridComboBoxColumn'. I've tried a lot, but nothing really works. Here is what I have: viewmodel-class: public class ViewModel { public ViewModel() { TestCollection= new ObservableCollection<MyEnum>(); AnyClasses = new ObservableCollection<AnyClass>(); //... fill AnyClasses with stuff... TestCollection.Add(MyEnum.Value1); TestCollection.Add(MyEnum.Value2); TestCollection.Add(MyEnum.Value3); TestCollection.Add(MyEnum.Value4); TestCollection.Add

Can an xsd:enumeration tag be made mandatory/required?

房东的猫 提交于 2019-12-12 19:41:00
问题 Short-form question: Can an xsd:enumeration tag have a required attribute, as in any tag that uses this enumeration MUST use the specific enumeration value at least once? Details: For example, let's say that I have already defined a fruit xml tag in my xsd. The fruit tag has an attribute whose value is the enumeration FruitType. It is define as such: <xsd:simpleType name="FruitType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Apple" /> <xsd:enumeration value="Banana" /> <xsd