定义枚举.h中:
#import <Foundation/Foundation.h>
// C语言枚举定义
//typedef enum{
// XMGTopicTypeImage=10, //图片
// XMGTopicTypeWord=29, // 段子
// XMGTopicTypeVoice=31, // 声音
// XMGTopicTypeVideo=41, ///视频
//} XMGTopicType;
// IOS 新的推荐写法
typedef NS_ENUM(NSUInteger, XMGTopicType) {
XMGTopicTypeImage=10, //图片
XMGTopicTypeWord=29, // 段子
XMGTopicTypeVoice=31, // 声音
XMGTopicTypeVideo=41, ///视频
} ;
@interface Person : NSObject
-(void ) show :(XMGTopicType) xmgtopicType;
@end
.m中写法:
#import "Person.h"
@implementation Person
-(void ) show :(XMGTopicType) xmgtopicType{
switch (xmgtopicType) {
case XMGTopicTypeVoice:
NSLog(@"%@",@"XMGTopicTypeVoice");
break;
case XMGTopicTypeImage:
NSLog(@"%@",@"XMGTopicTypeImage");
break;
case XMGTopicTypeWord:
NSLog(@"%@",@"XMGTopicTypeWord");
break;
case XMGTopicTypeVideo:
NSLog(@"%@",@"XMGTopicTypeVideo");
break;
}
}
@end
使用枚举:
导入Person.h头文件,那么枚举类型自动导入:
- (IBAction)showError:(id)sender {
Person* person =[[Person alloc] init];
[person show:XMGTopicTypeImage];
}