I would assume this to be easy but it's not working. I have an array I want to remove an objet from. Object is of a type protocol.
var myArray = Array<MyProtocol>()
myArray.remove(at: protocolToRemove)
From another SO question I saw a proposal for Array extension but it's not working when I put the extension in another file.
extension Array where Element: Equatable {
// Remove first collection element that is equal to the given `object`:
mutating func remove(object: Element) {
if let index = index(of: object) {
remove(at: index)
}
}
}
The protocol does not implement Equatable
Edit - Adding more information
MyProtocol Looks like
protocol MyProtocol {
}
Also tried this, but MyProtocol is not AnyObject, even with the class only protocol.
extension Array where Element: AnyObject {
mutating func remove(_ element: Element) {
guard let index = index(where: { $0 === element }) else { return }
remove(at: index)
}
func test() {
}
}