2017-10-06 107 views
1

虽然迁移到Swift 4.0,我面临着@IBInspectable问题,@IBInspectable在雨燕4.0

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出了什么问题。

此外,编译器没有显示任何建议。它只是显示一条错误消息。

+2

的错误是真的很明显。即使它通过了编译,在Swift 3中也确实无法工作。界面生成器中的编辑如何在Swift 3中找到你? – Sulthan

+3

协议是否是类协议?并标记了“@ objc”?另请注意,代表应该是“弱”的。 – Sulthan

+0

如果你想在IB中连接它们,它们应该是'@ IBOutlet's,而不是'@ IBInspectable' –

回答

0

添加符号@objc两个委托和数据源在夫特4(如下代码中所示)

open class SVContactBubbleView: UIView { 
    @IBInspectable open var dataSource: SVContactBubbleDataSource? 
    @IBInspectable open var delegate: SVContactBubbleDelegate? 
} 

@objc // add notation here 
public protocol SVContactBubbleDataSource 
{ 
    //Methods here 
} 


@objc // add notation here 
public protocol SVContactBubbleDelegate 
{ 
    //Methods here 
} 


这里是参考文献快照与错误解决:

enter image description here

这里是苹果文档@objc符号 - Protocol - Optional Protocol Requirements