What is the difference between NS_ENUM and NS_OPTIONS?

前端 未结 4 1401
轻奢々
轻奢々 2021-01-30 04:47

I preprocessed following code with clang in Xcode5.

typedef NS_ENUM(NSInteger, MyStyle) {
    MyStyleDefault,
    MyStyleCustom
};

typedef NS_OPTIONS(NSInteger,         


        
4条回答
  •  盖世英雄少女心
    2021-01-30 04:47

    The only major difference is that using the appropriate macro allows Code Sense (Xcode's code completion) to do type checking and code completion better. For example, NS_OPTIONS allows the compiler to make sure all the enums you | together are of the same type.

    For further reading see: http://nshipster.com/ns_enum-ns_options/

    Edit:

    Now that Swift is coming, using NS_ENUM/OPTIONS is highly recommended so that the enum can be correctly bridged to a swift enum.

提交回复
热议问题