I would like to wire up a custom swift delegate in IB. The delegate is an object that implements a certain protocol in swift.
protocol ThumbnailTableViewCel
It kind of makes sense that IB requires AnyObject, rather than your particular protocol. The object you want to connect to probably, but not necessarily conforms to the protocol, and the protocol may have optionals - so:
Make your protocol like this:
@objc public protocol HexViewDataSource: NSObjectProtocol {
@objc optional func dataAtOffset (_ hexView: HexView, offset: UInt64, length: Int)-> Data?
@objc optional func dataLength (_ hexView: HexView) -> UInt64
}
Declare it in your class like this, for instance:
@IBOutlet weak open var dataSource: AnyObject?
And when you come to use it, check that it conforms to the protocol and that the optionals exist - like this:
if let dataSource = dataSource as? HexViewDataSource, let dfr = dataSource.dataAtOffset {
setRowData(offset: offset, data: dfr (self, offset, bytesPerRow))
}