Hello,
What is the situation regarding the "remove item from array" problem in Swift 2.0?
Of course there is the find index function in the language guide (an example of generics) but that's not very object-oriented
On Stackoverflow I have seen two answers:
1. Make an Array extension that bridges to NSArray and use indexOfObject (ugly, but works in Swift 1.2 too)
2. Extend the
RangeReplaceableCollectionType protocol in Swift 2.0extension RangeReplaceableCollectionType where Generator.Element : Equatable { mutating func removeObject(object:Self.Generator.Element) { if let found = self.indexOf(object) { self.removeAtIndex(found) } } }Does this really work?It would be so much nicer if you could do
extension Array<T:Equatable>
{
mutating func removeItem<T:Equatable>(item:T) { if let index = find(self,object) {removeAtIndex(index) }}
}
in order to have a removeItem method for arrays of an Equatable type
Jan E.