I have an NSMutableArray oldArray . Now, at some point, this NSMutableArray updated with another NSMutableArray , which may have more, less, or the same number of elements than the previous NSMutableArray .
I want to compare old and new arrays with changes. I want two NSArray addedArray and removedArray that will contain the indices of the elements that were added and / or removed from the old array.
All this problem will be more clear on an example:
oldArray = {@"a",@"b",@"d",@"e",@"g"}; newArray = {@"a",@"c",@"d",@"e",@"f",@"h"};
So, here the deleted objects are @ "b" and @ "g" at indices 1 and 4, respectively. Added objects @ "c", @ "f" and @ "h" at indices 1, 4 and 5 (the first objects are deleted and then added).
Thus,
removedArray = {1,4}; and addedArray = {1,4,5};
I need an efficient way to get these two arrays - removedArray and addedArray from the old and new NSMutableArray . Thank you If the problem is not very clear, I am ready to provide additional information.
Change 1
It might be more clear if I explain what I want to use for this.
In fact, for this, I update the UITableView using the insertRowsAtIndexPaths and removeRowsAtIndexPaths with animation after the table loads, so that the user can see that the deleted rows are coming out and new rows appear. tableview stores Favorites that a user can add or remove. Therefore, after adding some favorites and deleting some; when the user returns to the favorites tableview, animations will be shown.
Edit 2
It should be mentioned earlier, but the elements of both the old and the new arrays will be in ascending order. Only deletion or addition rates are considered. Order cannot be changed. ex. {@ "b", @ "a", @ "c", @ "d"} cannot be an array.