jflinter / Dwifft

Swift Diff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question from the Slow Lane

wm-j-ray opened this issue · comments

@jflinter,

First thank you for this brilliant library. Like many, I have been struggling with the problems your code solves for years, first in ObjC and now Swift. Previously TLIndexPathTools has been my library of choice but it is in ObjC and I would love to transition over.

But, I have a request...(it's for yet another demo).

I am struggling with insertions and deletions and I can't seem to figure out how they work using Dwifft. Can you point me to (or put up) another multiSection viewController example that has the traditional NavBar Edit button that would enable drag and drop, deletions (and, stretch request, inserts) so slow learners like me can see exactly how to wire up Dwifft+UIKit?

I get the didSet but I can't seem to get a handle on all the rest of what Dwifft can really do. I am assuming that SectionedValues IS the one and only model. Is that the case?

Thank you in advance

Hey @wm-j-ray,

Thanks for the kind words, and apologies for the very slow reply. I don't have a lot of time to work on Dwifft or help with integrations right now, so I'm afraid I can't help write any example code for you.

In general, the way I would think about TableViewDiffCalculator and friends is that they drive insertions/deletions to a UITableView when their rows or sectionedValues property changes. (If your table view only has a single section, I suggest looking at SingleSectionTableViewDiffCalculator as the API is slightly easier to understand.) So, when your underlying data changes (you get some new data from your API or whatever) you should make either an array of YourModels (for a single section) or a SectionedValues<YourSection, YourModel> (for multiple sections) and then update the rows/sectionedValues property of your diff calculator, and it will handle all of the UI updates for you. You should not manually insert/move/etc any rows on your table view, as that could lead to an inconsistent state and cause a crash.

I hope that makes things clearer, best of luck with your integration.