0

I am using keyboard selection in Swift for textfields and I need to show enum name (emailAdress...) in @IBInspectable instead of its Int number (0-6). How can I fix this?

  public class TextFieldView: UIView{

     enum KeyboardType: Int {
            case normal
            case asciiCapable
            case numberPad
            case phonePad
            case emailAddress
            case namePhonePad
        }

      @IBInspectable public var keyBoard: Int = 0 {
            didSet {
                let keyBoardType = KeyboardType(rawValue: keyBoard)
                self.textField.keyboardType = UIKeyboardType.init(rawValue: keyBoardType!.rawValue)!

            }
    }
David Ruland
  • 103
  • 2
  • 13
  • Does this answer your question? [How to create an IBInspectable of type enum](https://stackoverflow.com/questions/27432736/how-to-create-an-ibinspectable-of-type-enum) – Guilherme Matuella Mar 14 '20 at 12:31

1 Answers1

0

use CustomStringConvertible

enum KeyboardType: Int, CustomStringConvertible {
     case normal = 0
     case asciiCapable = 1
     case numberPad = 2
          ...

     var description: String {
          switch self {
       case .normal:
          return "normal"
       case .asciiCapable:
          return "asciiCapable"
           ...
          }
    }
Hoven
  • 563
  • 1
  • 5
  • 24