Adr*_*ian 17 xcode swift swift4 xcode9-beta
在Xcode 9和Swift 4中,我总是会收到一些IBInspectable
属性的警告:
@IBDesignable public class CircularIndicator: UIView {
// this has a warning
@IBInspectable var backgroundIndicatorLineWidth: CGFloat? { // <-- warning here
didSet {
backgroundIndicator.lineWidth = backgroundIndicatorLineWidth!
}
}
// this doesn't have a warning
@IBInspectable var topIndicatorFillColor: UIColor? {
didSet {
topIndicator.fillColor = topIndicatorFillColor?.cgColor
}
}
}
Run Code Online (Sandbox Code Playgroud)
有办法摆脱它吗?
dfd*_*dfd 27
也许.
我在复制/粘贴类时得到的确切错误(不是警告)CircularIndicator: UIView
是:
属性不能标记为@IBInspectable,因为其类型无法在Objective-C中表示
我通过进行此更改解决了这个问题:
@IBInspectable var backgroundIndicatorLineWidth: CGFloat? { // <-- warning here
didSet {
backgroundIndicator.lineWidth = backgroundIndicatorLineWidth!
}
}
Run Code Online (Sandbox Code Playgroud)
至:
@IBInspectable var backgroundIndicatorLineWidth: CGFloat = 0.0 {
didSet {
backgroundIndicator.lineWidth = backgroundIndicatorLineWidth!
}
}
Run Code Online (Sandbox Code Playgroud)
当然,backgroundIndicator
在我的项目中未定义.
但是如果您正在编码didSet
,看起来您只需要定义默认值而不是backgroundIndicatorLineWidth
可选.
以下两点可能对您有所帮助
由于目标c中没有可选概念,因此可选的IBInspectable会产生此错误.我删除了可选项并提供了默认值.
如果您使用的是某些枚举类型,请在该枚举之前编写@objc以删除此错误.
斯威夫特 - 5
//Change this with below
@IBInspectable public var shadowPathRect: CGRect!{
didSet {
if shadowPathRect != oldValue {
setNeedsDisplay()
}
}
}
Run Code Online (Sandbox Code Playgroud)
到
@IBInspectable public var shadowPathRect: CGRect = CGRect(x:0, y:0, width:0, height:0) {
didSet {
if shadowPathRect != oldValue {
setNeedsDisplay()
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9831 次 |
最近记录: |