You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letstagedChangeset=StagedChangeset(source: dataStore.elements, target: newElements)
for changeset in stagedChangeset {
dataStore.elements = changeset.data
varsnapshot= dataSource.snapshot()// What to do here?
dataSource.apply(snapshot, animatingDifferences: true)}
While each element can be Identifiable to provide identifiers for the various snapshot methods, it is not clear how to process the changesets.
Please explain in detail how to accomplish this or kindly consider adding methods to the library similar to the existing UIKit/AppKit extensions. Thank you!
The text was updated successfully, but these errors were encountered:
The temporary workaround shown below replaces all the identifiers and appears to work, however I am still seeking a solution to apply the deleted/inserted/updated/moved sections and elements for optimum performance.
extensionNSDiffableDataSourceSnapshot{// MARK: - With Sectionspublicmutatingfunc apply<T,U>(
_ changeset:Changeset<[ArraySection<T,U>]>)where T:Identifiable, T.ID ==SectionIdentifierType, U:Identifiable, U.ID ==ItemIdentifierType{deleteAllItems()appendSections(changeset.data.map(\.model).map(\.id))
for arraySection:ArraySection in changeset.data {appendItems(arraySection.elements.map(\.id), toSection: arraySection.model.id)}reloadSections(changeset.sectionUpdated.map{ offset insectionIdentifiers[offset]})letitems:[ItemIdentifierType]= changeset.elementUpdated.map{ path initemIdentifiers(inSection:sectionIdentifiers[path.section])[path.element]}
if #available(iOS 15.0,*){reconfigureItems(items)}else{reloadItems(items)}}// MARK: - Without Sectionspublicmutatingfunc apply<T>(
_ changeset:Changeset<T>)where SectionIdentifierType ==Int, T.Element:Identifiable, T.Element.ID ==ItemIdentifierType{deleteAllItems()appendSections([0])appendItems(changeset.data.map(\.id))letitems:[ItemIdentifierType]= changeset.elementUpdated.map{ path initemIdentifiers[path.element]}
if #available(iOS 15.0,*){reconfigureItems(items)}else{reloadItems(items)}}}
Checklist
Detailed Description
How to use
DifferenceKit
with diffable data sources?While each element can be Identifiable to provide identifiers for the various
snapshot
methods, it is not clear how to process the changesets.Please explain in detail how to accomplish this or kindly consider adding methods to the library similar to the existing UIKit/AppKit extensions. Thank you!
The text was updated successfully, but these errors were encountered: