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

Troubles with API #46

Open
psi-gh opened this issue Aug 20, 2019 · 2 comments
Open

Troubles with API #46

psi-gh opened this issue Aug 20, 2019 · 2 comments

Comments

@psi-gh
Copy link

psi-gh commented Aug 20, 2019

For example, in my code i have a very common case:

protocol BaseClassProtocol { }
class ConcreteClass1: BaseClassProtocol { } 
class ConcreteClass2: BaseClassProtocol { }

Anywere in my codebase, there is only BaseClassProtocol being used. For example:

let array:[BaseClassProtocol] = ...

this array contains various classes/structs with the same protocol.
How can I apply DeepDiff library and DiffAware protocol to compare various arrays of BaseClassProtocol objects?

@Voxar
Copy link

Voxar commented Sep 27, 2019

Create a wrapper struct that implements DiffAware

struct DiffWrapper: DiffAware {
  var item: BaseClassProtocol
  var diffId: String {
    return item.id
  }
  static func compareContent(_ a: DiffWrapper, _ b: DiffWrapper) -> Bool {
    return a.item == b.item
  }
}
let changes = diff(old.map(DiffWrapper.init), new.map(DiffWrapper.init))

@psi-gh
Copy link
Author

psi-gh commented Sep 27, 2019

@Voxar Yeah, I came up with the similar structure. I asked because I don't like this overhead. But I understand there are some Swift's nuances which leads to difficulties in such kind of API.

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

2 participants