I
I
Ivan Vorobei2019-11-02 12:38:51
Swift
Ivan Vorobei, 2019-11-02 12:38:51

How to track changes in an array, split into insert/delete and update?

Live example, let's declare an array:
var array = [John, Omega, Alpha, Toster]
Something happened and the array changed:
var newArray = [John, Alpha, Toster]
We need to get the difference, an element was removed from the array at index 1, added at index..., modified at index...
It is necessary to show changes in the table animatedly using insert methods, delete & reload, and I don’t want to pull the reactive for this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2019-11-02
@ivanvorobei

5dbd5546661d4815276402.png

Code
["John", "Alpha", "Toster"]
  .difference(from: ["John", "Omega", "Alpha", "Toster"])
  .forEach { print($0) }

// remove(offset: 1, element: "Omega", associatedWith: nil)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question