I have two structs like this
struct LastKey:Equatable, MyProtocol {
var id: UUID
let lowercase:String?
var isValid:Bool {
// calculate
}
}
struct FirstKey:Equatable, MyProtocol {
var id: UUID
let name:String?
}
protocol MyProtocol {
var id:UUID { get set }
}
Then I decided to use this
func setLastKey(_ lastKey:MyProtocol) {
let lastKey = LastKey()
if lastKey.isValid { // do something }
}
But because lastKey
is of type MyProtocol
, and isValid
is not on the protocol I have to add it as optional, because firstKey
doesn’t have this property.
If I change the protocol to
@objc protocol MyProtocol {
var id:UUID { get set }
@objc optional var isValid:Bool { get set }
}
then the structs whine with the following error:
Non-class type 'FirstKey' cannot conform to class protocol 'MyProtocol'
Non-class type 'LastKey' cannot conform to class protocol 'MyProtocol'