Getting total number of enum items

c, enums, objective-c

Solution

An `enum` is a plain-old-C type, therefore it provides no dynamic runtime information.

One alternative is to use the last element of an enum to indicate the count:

typedef enum {
    Red,
    Green,
    Blue,
    numColors
} Color;

Problem

Is it possible to get the total number of items defined by an enum at runtime? While it's pretty much the same question as this one, that question relates to C#, and as far as I can tell, the method provided there won't work in Objective-C.

Original source

Related problems