1

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.

Krunal
  • 77,632
  • 48
  • 245
  • 261
PGDev
  • 23,751
  • 6
  • 34
  • 88
  • 2
    The error is really obvious. In really could not work in Swift 3, even if it passed the compilation. How did the editor in interface builder looked for you in Swift 3? – Sulthan Oct 06 '17 at 07:57
  • 3
    Are the protocols `class` protocols? and marked `@objc`? Also note that delegates should probably be `weak`. – Sulthan Oct 06 '17 at 09:45
  • If you want to connect them up in IB, they should be `@IBOutlet`s, not `@IBInspectable` – Ashley Mills Oct 10 '17 at 09:22

1 Answers1

1

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:

enter image description here

Here is Apple document for @objc notation - Protocol - Optional Protocol Requirements

Krunal
  • 77,632
  • 48
  • 245
  • 261