Can't connect delegate property of CustomView
declared as @IBOutlet toViewController
in Interface Builder – simply can't establish a connection.
Here's the code
class CustomView: UIView {
@IBOutlet var delegate: CustomViewDelegate?
}
@objc protocol CustomViewDelegate {
...
}
class ViewController: UIViewController, CustomViewDelegate {
...
}
@objc
is used because of swift protocol, IBOutlet property cannot have non-object type, don't know why protocol CustomViewDelegate: class {}
doesn't work.
Anyone else came across something like that?
UIViewController
in Interface Builder have its class specifically set toViewController
? Also, it's normally a requirement (last I checked) that@IBOutlet
properties be defined as implicitly unwrapped types, like so:CustomViewDelegate!
. This allows them to benil
at instantiation, while allowing you to use them without optional binding after they've been wired up. – Frilling