When I create an array of protocol types, how would I get the index of an object in this array? I tried the following:
protocol aProtocol {
func doSomething()
}
class aClass: aProtocol, Equatable {
var aProperty = "test"
func doSomething() {
}
}
func == (lhs: aClass, rhs: aClass) -> Bool {
return lhs.aProperty == rhs.aProperty
}
var testArray = aProtocol[]()
let testObject = aClass()
testArray += testObject
find(testArray, testObject)
In this case, I get the message "Unable to convert expression type" $ T4? "to enter the error" aClass ".
Looking for the signature of the find () method, we find that the element must implement Equatable (which is why I overload the == operator above):
func find<C : Collection where C.GeneratorType.Element : Equatable>(domain: C, value: C.GeneratorType.Element) -> C.IndexType?
Does anyone have an idea of what I'm doing wrong, or if this scenario is possible? Thank.
source
share