The interface for the function find
is/was:
func find<C : CollectionType where C.Generator.Element : Equatable>(domain: C,
value: C.Generator.Element) -> C.Index?
This says that the CollectionType
of C
must have elements that are Equatable
and, furthermore, that the value
must also be Equatable
.
[Note Swift 3.0: As of Swift 3.0, you'll need to use the index
function which comes in two variations. In the first, you'll supply your own predicate:
func index(where: (Self.Generator.Element) -> Bool) -> Self.Index?
In the second, your elements need to be equatable:
// Where Generator.Element : Equatable
func index(of: Self.Generator.Element) -> Self.Index?
If you decide to go the equatable
route, then the following applies.
Note End]
Your Score
struct is not Equatable
and hence the error. You'll need to figure out what it means for scores to be equal to one another. Maybe it is some numerical 'score'; maybe it is a 'score' and a 'user id'. It depends on your Score
abstraction. Once you know, you implement ==
using:
func == (lhs:Score, rhs:Score) -> Bool {
return // condition for what it means to be equal
}
Note: if you use class
and thus scores have 'identity' then you can implement this as:
func == (lhs:Score, rhs:Score) -> Bool { return lhs === rhs }
Your example with strings works because String
is Equatable
. If you look in the Swift library code you'll see:
extension String : Equatable {}
func ==(lhs: String, rhs: String) -> Bool