Perhaps if the indexes are continuous using the removeSubrange method. For example, if you want to remove items with an index of 3 - 5:
myArray.removeSubrange(ClosedRange(uncheckedBounds: (lower: 3, upper: 5)))
For non-continuous indexes, I would recommend removing items with a larger index to a smaller one. There is no benefit that I could think of deleting items "at the same time" in the same layer, except that the code may be shorter. You can do this using the extension method:
extension Array { mutating func remove(at indexes: [Int]) { for index in indexes.sorted(by: >) { remove(at: index) } } }
Then:
myArray.remove(at: [3, 5, 8, 12])
UPDATE: using the solution above, you need to make sure that the index array does not contain duplicate indexes. Or you can avoid duplicates as shown below:
extension Array { mutating func remove(at indexes: [Int]) { var lastIndex: Int? = nil for index in indexes.sorted(by: >) { guard lastIndex != index else { continue } remove(at: index) lastIndex = index } } } var myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] myArray.remove(at: [5, 3, 5, 12])