While migrating to Swift 4.0
, I am facing an issue with @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
}
The error that appears is:
Property cannot be marked @IBInspectable because its type cannot be represented in Objective-C
In Swift 3
, it was working fine. I don't understand what went wrong in Swift 4
.
Also, the compiler is not showing any suggestion. It just shows an error message.
Add notation @objc for both delegate and datasource in Swift 4 (as shown in below code)
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
}
Here is ref. snapshot with error resolution:
Here is Apple document for @objc
notation - Protocol - Optional Protocol Requirements