Raw value for enum case must be a literal

后端 未结 4 1141
花落未央
花落未央 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:24

    Swift 2.2 Version : In my case I needed to Convert the String Enum Values to be used in Localisable Strings. So added this method inside my enum.

        enum DisplayCellTitle: String {
        case Clear 
    
        func labelTitle() -> String {
            switch self {
            case .Clear:
                return "LBL_CLEAR".localizedWithComment("Clear")
            }
        }
    }
    

    And then Use it like so :

            // Get the localised value of the Cell Label Title
        let lblTitle = DisplayCellTitle.labelTitle(cellTitle)()
    

    where cellTitle passed in is just one of these CellTitle Enum Values

提交回复
热议问题