Chibimagic's Weblog

Archive for February 2015

You can put primitives in an NSArray or NSDictionary by packing them with the @() syntax. For example:

typedef enum {
    MyEnumOne,
    MyEnumTwo
} MyEnum

NSDictionary *dictionary = @{
                             @(MyEnumOne) : @"one",
                             @(MyEnumTwo) : @"two"
                             };

But how do you then use this with fast enumeration? Turns out, the @() syntax creates a boxed NSNumber. Therefore, when enumerating, access it as an NSNumber. To cast it back to an enum, first extract the integer value, then cast:

for (NSNumber *number in dictionary) {
    MyEnum myEnum = (MyEnum)[number intValue];
    ...
}


  • Marketing Consultant: You're an great writer. You have brought up some really interesting insights. Just wanted to say fantastic blogs! I know tons of people see your write
  • optical franchise opportunities: Right now it looks like Wordpress is the preferred blogging platform out there right now. (from what I've read) Is that what you are using on your blo
  • startup speaker: Interesting content. A magnificent article. It is very informative and you are obviously very knowledgeable in this area.

Categories