'ViewController' 不能转换为 'CocoaMQTTDelegate'?

'ViewController' is not convertible to 'CocoaMQTTDelegate'?

我正在尝试使用 CocoaMQTT 建立连接。 GitHub 页面上提供了以下示例:

https://github.com/emqx/CocoaMQTT/blob/master/Example/Example/ViewController.swift

他们使用视图控制器 'self' 作为委托(参见第 53/63/74 行)。但是,当我尝试将视图控制器用作委托时,出现错误:

Cannot assign value of type 'ViewController' to type 'CocoaMQTTDelegate?'

我试过使用以下方法转换它:

self as! CocoaMQTTDelegate

但是没有骰子。

在示例中,他们对 iOS 使用 ViewController: UIViewController,而我对 macOS 使用 ViewController: NSViewController,这是否会导致问题?我是 Swift 的新手,所以非常感谢任何帮助。 (这是一个 iOS/macOS/tvOS 库)。

有什么想法吗?

感谢@Vollan 建议在文件底部添加扩展名。我可能应该注意到这一点。我的错。