How to list an enumeration in Objective-C?

Possible duplicate:
looping enumeration values

Suppose we are dealing with a deck of cards

typedef enum { HEARTS, CLUBS, DIAMONDS, SPADES, SUIT_NOT_DEFINED } Suit; 

How can I list the listing?

+6
source share
1 answer

You can use the lower bound of enum as the starting point and check that the loop condition is against the upper bound:

 for(int i = HEARTS; i < SUIT_NOT_DEFINED; ++i) { //do something with i... } 
+6
source

Source: https://habr.com/ru/post/903159/


All Articles