removeObjectsAtIndexes for Swift arrays

前端 未结 14 1223
长情又很酷
长情又很酷 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 13:03

    To complete Ethan's answer, C-loop styles will be deprecated in Swift 3.0. Here's then a Swift 3.0 compatible answer:

    mutating func removeAtIndexes(indexes: NSIndexSet) {
        var i = indexes.lastIndex
        while i != NSNotFound {
            self.removeAtIndex(i)
            i = indexes.indexLessThanIndex(i)
        }
    }
    

提交回复
热议问题