Objective-C
//NS_ENUM,定義狀態等普通枚舉
typedef NS_ENUM(NSUInteger, TTGState) {
TTGStateOK = 0,
TTGStateError,
TTGStateUnknow
};
//NS_OPTIONS,定義選項
typedef NS_OPTIONS(NSUInteger, TTGDirection) {
TTGDirectionNone = 0,
TTGDirectionTop = 1 << 0,
TTGDirectionLeft = 1 << 1,
TTGDirectionRight = 1 << 2,
TTGDirectionBottom = 1 << 3
};
參考
http://blog.csdn.net/annkie/article/details/9877643
http://blog.csdn.net/annkie/article/details/9877643
Swift
//簡易定義:首字母大寫
enum Color {
case blue
case red
case green
case gray
case white
case black
}
//複雜定義
enum ColorWithDesc:String {
case blue = "藍色"
case red = "紅色"
case green = "綠色"
case gray = "灰色"
case white = "白色"
case black = "黑色"
}
參考
http://www.99ios.com/index.php/archives/3153/
http://www.99ios.com/index.php/archives/3153/
留言
張貼留言