1

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.

Brian
  • 3,571
  • 7
  • 44
  • 70

3 Answers3

6

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.

Darren
  • 25,520
  • 5
  • 61
  • 71
  • It's a bit more subtle than this. The enum type itself is the compiler-dependent integral type that may be smaller than `int`. But the enum *values* are actually just integral constants. – Lily Ballard Feb 10 '12 at 21:13
1

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

Zenexer
  • 18,788
  • 9
  • 71
  • 77
Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
0

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.

Community
  • 1
  • 1
barfoon
  • 27,481
  • 26
  • 92
  • 138
  • But what is the range of values that an enumeration can have. Also, if a method was being passed a value from an enumeration but did not know it, what would the type of the parameter be. – Brian Feb 10 '12 at 18:40
  • It would be the type of what ever you define the enum to be. – barfoon Feb 10 '12 at 18:43