枚举类型
#import <Foundation/Foundation.h>
// 枚举类型
enum Month{january, february = 10, march = 10, april, may, june, july,
august, september, october, november, december};
int main(int argc, const char * argv[]) {
@autoreleasepool {
enum Month month = january;
month = october;
switch(month)
{
case january:
NSLog(@"一月");
break;
case february:
NSLog(@"二月");
break;
case 9: // october
NSLog(@"十月");
break;
default:
NSLog(@"其他月份");
break;
}
month = (enum Month)10;
// 如果多个枚举值共享一个整数,枚举变量相当于同时等于多个枚举值
if(month == march)
{
NSLog(@"三月");
}
NSLog(@"month = %d", month);
NSLog(@"month = %d", february);
// 隐式定义枚举类型
enum {east, west, south, north} direction = east;
}
return 0;
}