几天前曾尝试使用Xcode 10的应用程序和Swift 4.1中的Swift 4.2,但是我无法解决使用4.2版Swift时遇到的错误 .
Having this protocol used in my application
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
}
}
The way it's used in the view model of my app
private var data: [MyProtocol] = []
它给了我一个错误 .
Protocol 'MyProtocol' can only be used as a generic constraint because it has Self or associated type requirements