What is a Swift array equivalent to NSMutableArray
\'s -removeObjectsAtIndexes:
? Removing each index one by one doesn\'t work, as remaining indexes
I have not tested this, but I would bet that a non-mutating version is faster if it copies contiguous subranges. Something like:
extension Array {
public func removing(indices indicesToRemove: IndexSet) -> Self {
guard let lastIndex = indicesToRemove.last else {
return self
}
assert(lastIndex <= (self.count - 1), message: "Index set contains out of bounds indices")
var result = Self()
result.reserveCapacity(self.count - indicesToRemove.count)
let indicesToKeep = IndexSet(self.indices).subtracting(indicesToRemove)
let rangesToKeep = indicesToKeep.rangeView
rangesToKeep.forEach { (range) in
result.append(contentsOf: self[range])
}
return result
}
}