手机APP开发 2017-03-19
如果一个变量只有几种可能的值,比如星期有几天,一年有几个季节等。这个时候可以用枚举变量。
//
// Enum_Test.h
// Test
//
// Created by 程英暾 on 2017/3/19.
// Copyright © 2017年 程英暾. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Enum_Test : NSObject
{
//参数
@public
enum siji{chun=,xia= ,qiu= ,dong= };//定义枚举变量
}//参数over
-(void)DuiBi;//对比
@end// Enum_Test.m
// Test
//
// Created by 程英暾 on 2017/3/19.
// Copyright © 2017年 程英暾. All rights reserved.
//
#import "Enum_Test.h"
@implementation Enum_Test
-(void)DuiBi{
NSLog(@"春的值为:%d",chun);
NSLog(@"秋的值为:%d",qiu);
if(xia<dong)
{
NSLog(@"冬天比夏天冷");
}
};
@end#import <Foundation/Foundation.h>
#import "Enum_Test.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Enum_Test *enum_test=[[Enum_Test alloc]init];//实例化类
[enum_test DuiBi];//调用累的方法
}
return 0;
} -------------------Result--------------------2017-03-19 21:03:55.728893 Test[6525:250697] 春的值为:1
2017-03-19 21:03:55.728934 Test[6525:250697] 秋的值为:3
2017-03-19 21:03:55.728957 Test[6525:250697] 冬天比夏天冷
Program ended with exit code: 0