Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

How to apply the changes to old-array #68

Open
GloamZz opened this issue Jul 6, 2022 · 2 comments
Open

How to apply the changes to old-array #68

GloamZz opened this issue Jul 6, 2022 · 2 comments

Comments

@GloamZz
Copy link

GloamZz commented Jul 6, 2022

In my situation, I make diffing between two different classes packaged by the same enum.
As:
enum PackagingEnum: DiffAware {
case a(ClassA)
case b(ClassB)

var diffId: Int {
    switch self {
    case a(let classA):
        return classA.hashValue
    case b(let classB)
        return classB.hashValue
    }
}

}
in this case, I want to make diffing [ClassA] to [ClassB] via DeepDiff.

but when I get the changes by 'diff(old: [Enum-B], new: [Enum-A])'

I traverse the changes, and invoke 'insert/remove/move' in [Enum-B](the old), I get crashed because of 'Out of Range'

@github-actions
Copy link

github-actions bot commented Jul 6, 2022

Message that will be displayed on users' first issue

@GloamZz
Copy link
Author

GloamZz commented Jul 6, 2022

For example
I diff [1, 2, 3, 4, 5] to [1]
I will get changes in order that [.delete(Index1), .delete(Index2), , .delete(Index3), , .delete(Index4)]
I traverse the changes in order
for change in changes { if case let .delete(delete) = change { old.remove(at: delete.index) } }
I will get crashed when remove index3 because of out of range.

Of course, I can sort the changes by index. But I can't convert the old to the new if the changes mixed with insert&move

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant