【发布时间】:2018-03-17 23:05:01
【问题描述】:
在迁移到 Swift 4.0 时,我遇到了 @IBInspectable 的问题,
open class SVContactBubbleView: UIView
{
@IBInspectable open var dataSource: SVContactBubbleDataSource? //ERROR..!!
@IBInspectable open var delegate: SVContactBubbleDelegate? //ERROR..!!
}
public protocol SVContactBubbleDataSource
{
//Methods here
}
public protocol SVContactBubbleDelegate
{
//Methods here
}
出现的错误是:
属性不能被标记为@IBInspectable,因为它的类型不能 用Objective-C表示
在Swift 3 中,它运行良好。我不明白Swift 4 出了什么问题。
此外,编译器没有显示任何建议。它只是显示一条错误消息。
【问题讨论】:
-
错误确实很明显。 In 真的不能在 Swift 3 中工作,即使它通过了编译。在 Swift 3 中,界面生成器中的编辑器是如何找到你的?
-
协议是
class协议吗?并标记为@objc?另请注意,代表可能应该是weak。 -
如果你想在 IB 中连接它们,它们应该是
@IBOutlets,而不是@IBInspectable
标签: ios delegates datasource swift4 ibinspectable