Hello I am using Term protocol as a Type for my structs so I can have a Statement struct with terms collection where I could store the rest of my structs. What I would like to do is, I would like to check for equality for the term in the array and the argument I pass in the function in the bottom. I know the WWDC session Building Better Apps with Value Types talking about Equatable protocol being implementing on a struct however in this instance I do have Term which is already a protocol. How would it work in this case?
Thanks in advance.
import Foundation
protocol Term {
var value: String { get }
}
extension Term {}
struct Statement {
var terms: [Term] = []
mutating func addItem(term: Term) {
terms.append(term)
}
}
struct Fraction: Term {
let numerator: Statement
let denominator: Statement
let value: String
}
struct Exponent: Term {
let base: String
let power: Statement
let value: String
}
struct Variable: Term {
let value: String
}
struct Operator: Term {
let value: String
}
struct Number: Term {
let value: String
}
func highlightTerm(term:Term) {
for(_, localTerm) in EnumerateSequence(statement.terms) {
//how can I check if
//term == localTerm?
}
}
protocol Equatable {
func ==(lhs: Self, rhs: Self) -> Bool
}
extension Term: Equatable { }
func ==(lhs: Term, rhs: Term) -> Bool {
return lhs.value == rhs.value
}
currently I get Extension of protocol 'Term' cannot have an inheritance clause at line 47