When using find to search the index of an object in a array:
var index = find(Store.allItems, myItem)
The compiler says that the Item class does not conform to protocol Equatable.
My Item class is an object, so in my opinion, coming from C#, the default equality comparer should be reference equality.
In Swift, It seems that you need to specify Equatable on each reference-type in order for find to work.
Also, you need to imlement the == operator so that it uses === to compare references:
func ==(a:Item, b:Item) -> Bool {
return a === b
}
Moreover, this last declaration must be top-level code, which disgust me...
I tried writing:
func ==(a:AnyObject, b:AnyObject) -> Bool {
return a === b
}
but it seems not to work.
Is there some faster and more elegant way to achieve standard equality comparing for objects?