Declaring and using a bit field enum in Swift

前端 未结 14 1996
余生分开走
余生分开走 2020-12-13 09:24

How should bit fields be declared and used in Swift?

Declaring an enum like this does work, but trying to OR 2 values together fails to compile:

enum         


        
14条回答
  •  执念已碎
    2020-12-13 09:52

    You can build a struct that conforms to the RawOptionSet protocol, and you'll be able to use it like the built-in enum type but with bitmask functionality as well. The answer here shows how: Swift NS_OPTIONS-style bitmask enumerations.

提交回复
热议问题