Reputation: 273
I have a protocol:
protocol ProfileManagerDelegete {
func dataHaveUpdated(type: ReturnType)
}
and create a protocol array, and add/remove listener:
var listeners: [ProfileManagerDelegete] = []
func addListener(listener: ProfileManagerDelegete) {
listeners.append(listener)
}
func removeLister(listener: ProfileManagerDelegete) {
for lis in listeners {
if lis == listener { // this line error
//remove listener
}
}
}
Anyone can help ?
Upvotes: 6
Views: 2304
Reputation: 4740
In this case, you want to use the '===' operator. Just make ProfileManagerDelegete conform to AnyObject.
Upvotes: 1
Reputation: 93151
Because you have not told Swift how to compare 2 objects of type ProfileManagerDelegete
. Define a function:
protocol ProfileManagerDelegete {
func dataHaveUpdated(type: ReturnType)
}
func == (lhs: ProfileManagerDelegete, rhs: ProfileManagerDelegete) -> Bool {
// decide if they are equal
}
Upvotes: 4