属性@IBInspectable无法标记

2 swift swift4

如何解决这个问题,安装xcode 9后告诉我这个

"无法将属性标记为@IBInspectable,因为其类型无法在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()
    }
}
Run Code Online (Sandbox Code Playgroud)

Yin*_*iet 19

您需要为枚举添加@objc:

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

@objc public enum Direction: Int {
        ...
}
Run Code Online (Sandbox Code Playgroud)

您确实需要Int基本类型,如果它是@objc样式,则不能为"空白" .