2

how to fix this problem, after installing xcode 9 show me this

"Property cannot be marked @IBInspectable because its type cannot be representing in Objective-c"

/// The mode of the gradient. The default is `.Linear`.
@IBInspectable open var mode: Mode = .linear {
    didSet {
        setNeedsDisplay()
    }
}

/// The direction of the gradient. Only valid for the `Mode.Linear` mode. The default is `.Vertical`.
@IBInspectable open var direction: Direction = .vertical {
    didSet {
        setNeedsDisplay()
    }
}
  • The error message is pretty clear – Sulthan Sep 23 '17 at 14:18
  • 2
    Possible duplicate of [How to create an IBInspectable of type enum](https://stackoverflow.com/questions/27432736/how-to-create-an-ibinspectable-of-type-enum) – Dávid Pásztor Sep 23 '17 at 14:29
  • Please edit your question to include code formatted as text using proper code formatting. Never include code as a screenshot in your questions. – Dávid Pásztor Sep 23 '17 at 14:30
  • Sorry, I edited. –  Sep 23 '17 at 14:43
  • Adding @objc in front of enum does silent the warning but does not make the property to show up in Attribute Inspector or User Defined Runtime Attributes in Identity Inspector. Instead I followed this https://stackoverflow.com/questions/27432736/how-to-create-an-ibinspectable-of-type-enum/46738871#46738871 to help solve the issue. It still is an issue in Swift 4.0/xcode 9. I also added my answer for backing variable (if needed inside the class for other computations). – Ohmy Oct 13 '17 at 22:47

1 Answers1

24

You need to add @objc for the enum:

@objc public enum Mode: Int {
        ...
}

@objc public enum Direction: Int {
        ...
}

You do need the Int base type, that can't be "blank" if it is an @objc style.

Fattie
  • 27,874
  • 70
  • 431
  • 719
YinKiet
  • 479
  • 6
  • 14