What is a Swift array equivalent to NSMutableArray
\'s -removeObjectsAtIndexes:
? Removing each index one by one doesn\'t work, as remaining indexes
Updated for Swift 2.0:
extension Array {
mutating func removeAtIndices(incs: [Int]) {
incs.sort(>).map { removeAtIndex($0) }
}
}
Use forEach
instead of map
if it gives a warning that the result isn't used (Since Swift 2 beta 6 I think)
EDIT: Super generic lazy solution:
extension RangeReplaceableCollectionType where Index : Comparable {
mutating func removeAtIndices(indices: S) {
indices.sort().lazy.reverse().forEach{ removeAtIndex($0) }
}
}