「iOS入門」列挙型(ENUM)の使い方

2018年5月13日

1.列挙型の宣言
typedef NS_ENUM(NSInteger, ChangFaType) {
ChangFaType1,
ChangFaType2
};

2. 文字列を取得
#define GetChangFaTypeText(type) ChangFaTypeTextList[type]

#define GetChangFaType(typeText) (ChangFaType)[ChangFaTypeTextList indexOfObject:typeText]

3.使用例–Switch
NSString *cftTypeText = @"first";
ChangFaType cftType = GetChangFaType(cftTypeText);

switch (cftType) {
case ChangFaType1:
{
//処理コード1
break
}
case ChangFaType2:
{
//処理コード2
break;
}

}

IOS

Posted by arkgame