Raw value for enum case must be a literal

后端 未结 4 1138
花落未央
花落未央 2021-02-06 22:38

I have this enum:

enum GestureDirection:UInt {
    case Up =       1 << 0
    case Down =     1 << 1
    case Left =     1 << 2
    case Right          


        
4条回答
  •  醉梦人生
    2021-02-06 23:09

    You seems to want a bitwise support for your enums, but if you regards a translation of NS_OPTIONS Objective-C in Swift, that's not represented by a Swift Enum but a struct inherit from RawOptionSetType.

    If you need example or instructions, you can look at this NSHipster article

    That's could be done with something like this :

    struct UIViewAutoresizing : RawOptionSetType {
        init(_ value: UInt)
        var value: UInt
        static var None: UIViewAutoresizing { get }
        static var FlexibleLeftMargin: UIViewAutoresizing { get }
        static var FlexibleWidth: UIViewAutoresizing { get }
        static var FlexibleRightMargin: UIViewAutoresizing { get }
        static var FlexibleTopMargin: UIViewAutoresizing { get }
        static var FlexibleHeight: UIViewAutoresizing { get }
        static var FlexibleBottomMargin: UIViewAutoresizing { get }
    }
    

    Regards,

提交回复
热议问题