removeObjectsAtIndexes for Swift arrays

前端 未结 14 1188
长情又很酷
长情又很酷 2020-11-30 12:34

What is a Swift array equivalent to NSMutableArray\'s -removeObjectsAtIndexes:? Removing each index one by one doesn\'t work, as remaining indexes

14条回答
  •  -上瘾入骨i
    2020-11-30 12:53

    Based upon Kent's solution but updated for Swift 3

    extension Array {
        mutating func remove(indices: IndexSet) {
            self = self.enumerated().filter { !indices.contains($0.offset) }.map { $0.element }
        }
    }
    

提交回复
热议问题