swift - 'ViewController' 不能转换为 '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
但没有骰子。
在示例中,他们使用的ViewController: UIViewController
是 iOS 版,而我使用的ViewController: NSViewController
是 macOS 版,这会导致问题吗?我对 Swift 很陌生,所以任何帮助都将不胜感激。(它是一个 iOS/macOS/tvOS 库)。
有任何想法吗?
解决方案
感谢@Vollan 建议在文件底部添加扩展名。我可能应该注意到这一点。我的错。
推荐阅读
- javascript - Puppeteer 在 Ubuntu 服务器上打开了太多的进程
- python-3.x - python turtle 模块中的推力和加速度问题
- r - 在R中将字符串修剪为特定字符
- android - 使用 Material 组件主题的 android 汉堡按钮颜色更改
- ios - 预期的数组,但在 Swift 中找到了 Dictionary
- java - 在 Spring Boot 应用程序中的内存 SQLITE 中不起作用
- amazon-web-services - 如何使用 CDK 创建包含多个语句的 IAM 策略?
- sql-server - 如果有数据,则加入表变量
- amazon-web-services - AWS SQS FIFO 队列事件源,是否支持 maximumBatchingWindowInSeconds?
- python - 使用 ArcGIS Pro conda 安装 OSMnx 错误