属性@IBInspectable无法标记

时间:2017-09-23 14:15:59

标签: 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()
    }
}

1 个答案:

答案 0 :(得分:15)

您需要为枚举添加@objc:

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

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

您需要Int基本类型,如果它是@objc样式,则不能为“空白”。

相关问题