I have an array of dictionaries and another array which contains indexes from which need to be removed from the first array. I tried making them IndexSet and using the removeObjects(at: indexes:IndexSet) but fails. Anyone has any idea how to do this?
print(listArray.count)
print(listToBeRemoved.count)`
let set = NSMutableIndexSet()
for (idx, index) in listToBeRemoved.enumerated(){
set.add((index as! NSIndexPath).row)
if idx == listToBeRemoved.count-1{
listArray.removeObjects(at: set as IndexSet)
}
print(listArray.count)
log prints: 111 24 87 but the problem is that the listArray contains the same object in of all its indexes. Before removing the objects all objects are different as intended.
ListArray is an array of dictionaries where dictionary has 4 keys:
{
Date = Date();
Source = String;
Title = String;
Url = String;
}
whereas listToBeRemoved is an array of IndexPaths e.g.:
(
"<NSIndexPath: 0xf7e2dd0ccbb6f985> {length = 2, path = 0 - 63}",
"<NSIndexPath: 0xf7e2dd0cc916f985> {length = 2, path = 0 - 42}",
"<NSIndexPath: 0xf7e2dd0cc936f985> {length = 2, path = 0 - 43}",
"<NSIndexPath: 0xf7e2dd0cc9b6f985> {length = 2, path = 0 - 47}",
"<NSIndexPath: 0xf7e2dd0cca56f985> {length = 2, path = 0 - 48}"
)
Any advice? Thanks in advance