2017-10-06 114 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