轉自 http://tutuge.me/2015/03/21/effective-objective-c-5-enum/
//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 };
因此,在開發Mac、iOS程序中,最好全部的枚舉都用「NS_ENUM」和「NS_OPTIONS」定義,保證統一。objective-c
充分的用好枚舉,能夠加強代碼的可讀性,減小各類「錯誤」,讓代碼更加的規範。spa