gpt4 book ai didi

swift - 如何修复 "' @IBInspectable' 属性对无法在 Objective-C 中表示的属性毫无意义“警告

转载 作者:IT王子 更新时间:2023-10-29 05:16:46 24 4
gpt4 key购买 nike

在 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
}
}
}

有没有办法摆脱它?

最佳答案

也许。

我在复制/粘贴类 CircularIndicator: UIView 时遇到的确切错误(不是警告)是:

Property cannot be marked @IBInspectable because its type cannot berepresented in Objective-C

我通过以下更改解决了这个问题:

@IBInspectable var backgroundIndicatorLineWidth: CGFloat? {  // <-- warning here
didSet {
backgroundIndicator.lineWidth = backgroundIndicatorLineWidth!
}
}

收件人:

@IBInspectable var backgroundIndicatorLineWidth: CGFloat = 0.0 {
didSet {
backgroundIndicator.lineWidth = backgroundIndicatorLineWidth
}
}

当然,backgroundIndicator 在我的项目中是未定义的。

但是如果您针对 didSet 进行编码,看起来您只需要定义一个默认值而不是将 backgroundIndicatorLineWidth 设为可选。

关于swift - 如何修复 "' @IBInspectable' 属性对无法在 Objective-C 中表示的属性毫无意义“警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46024160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com