【发布时间】:2018-02-08 03:59:54
【问题描述】:
如何解决这个问题,安装 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()
}
}
【问题讨论】:
-
错误信息很清楚
-
请编辑您的问题以包含使用正确代码格式格式化为文本的代码。切勿在问题中包含代码作为屏幕截图。
-
对不起,我编辑了。
-
在枚举前面添加@objc 会消除警告,但不会使属性显示在属性检查器中或身份检查器中的用户定义的运行时属性中。相反,我遵循了stackoverflow.com/questions/27432736/… 来帮助解决问题。这在 Swift 4.0/xcode 9 中仍然是一个问题。我还添加了我的支持变量的答案(如果需要在类中进行其他计算)。