removeObjectsAtIndexes for Swift arrays

前端 未结 14 1254
长情又很酷
长情又很酷 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 12:56

    I needed this for working with a NSTableview. This is what I use.

    extension Array{
    mutating func removeElementsAtIndexes(indexset:NSIndexSet){
        self = self.enumerate().filter({!indexset.containsIndex($0.index)}).map({$0.element})
        }
    }
    

提交回复
热议问题