Brian
Brian

Reputation: 3601

What is the type of a enum in Objective-C

I'm just trying to figure out if the values themselves are int, unsigned int, NSInteger. I thought I saw someone say that they were unsigned ints, but in Apple's header files I've seen them used to store negative values.

Upvotes: 1

Views: 446

Answers (3)

Alexsander Akers
Alexsander Akers

Reputation: 16024

Enumerated integers are 32-bit signed ints at the largest.

Upvotes: 1

Darren
Darren

Reputation: 25619

An enum is a feature of C (and C++), not Objective-C. When you declare an enum you declare a new C data type.

The size of a given enum data type may be the size of a int, or it may only be just large enough to hold each of the declared enum values. It's compiler specific, and there are usually compiler settings to control how enums are handled.

The largest an enum can be is int, so you can always convert any enum value to an int. The reverse is not true; you cannot necessarily convert any int to an enum value.

Upvotes: 6

barfoon
barfoon

Reputation: 28147

It's an enumerated type. You can define your own type that can take on certain specified values.

See this question: What is a typedef enum in Objective-C?

So if you had an enum like:

typedef enum {    
   NBType1,
   NBType2,
   NBType2,
} NBType

the parameter passed to a method would be of type NBType.

Upvotes: 0

Related Questions