swift - Protocol 'FlightRoutesDataProtocol' 只能用作通用约束,因为它具有 Self 或关联的类型要求
问题描述
几天前试图使用 Xcode 10 和 Swift 4.2 的应用程序,后者在 Swift 4.1 中更早,但无法解决我在使用 Swift 4.2 版本时遇到的错误。
在我的应用程序中使用此协议
protocol MyProtocol: AnyObject, RealmCollectionValue {
var name: String { get }
var count: Int { get }
static func sortKeyPath() -> String
func getTitleText() -> String
func getValueText() -> String
func getCodeText() -> String?
func getSubtitleText() -> String?
}
extension MyProtocol {
static func sortKeyPath() -> String {
return "count"
}
func getTitleText() -> String {
return name
}
func getValueText() -> String {
return "\(count)"
}
func getCodeText() -> String? {
return nil
}
func getSubtitleText() -> String? {
return nil
}
}
它在我的应用程序的视图模型中的使用方式
private var data: [MyProtocol] = []
它给了我一个错误。
协议“MyProtocol”只能用作通用约束,因为它具有 Self 或关联的类型要求
解决方案
推荐阅读
- html - 如何使用溢出自动仅停止第一个 li 在 ul li 列表中滚动?
- tensorflow - 如何更改 retrain.py 以获取 b64 图像
- python - 计算单词中字母的出现次数到熊猫数据框
- java - 我的 PITEST 不会运行。覆盖生成minion异常退出。我需要帮助才能正确配置我的 pom.xml
- python-3.x - pycharm 2019 优化导入后 Matplotlib 和 numpy 导入不起作用
- c# - 如何在不枚举数据的情况下进行异步查询?
- bash - 如何将多列拆分为几列?
- ocaml - 为什么只需要迭代有限流时这个程序不会停止?
- c# - 一对一关系 EF6 和主键的问题
- python - 如何将密码转换为哈希值?