I'm having trouble with Swift arrays. I want to add and remove items from an array in a single transaction when I have the indexes of items to add or remove.
array.insert(insertions.map({return (viewModels[$0], NSIndexPath(forRow: $0, inSection: 0))}))
array.remove(deletions.map{NSIndexPath(forRow: $0, inSection: 0)})
However when I remove the indexes, it breaks the order for adding items and adds them in the wrong position.
The idea would be something like:
array.update({
array.insert(insertions.map({return (viewModels[$0], NSIndexPath(forRow: $0, inSection: 0))}))
array.remove(deletions.map{NSIndexPath(forRow: $0, inSection: 0)})
})
Then combine them somehow, ideally I'd like to have multiple addition and removal capabilities.