Proper way to consume a reorder transaction?

I'm trying to digest the reorder transaction of an outline style collectionViewList where each section includes a header as its first item.

After the user performs the reorder I need to apply the transaction information to my data which is stored in core data. (It's an entity that contains a relationship to many instances of the same type - Parent + child)

When I reorder rows I see the following:

Moving rows within a section:

  • The transaction includes a sectionTransaction with no inserts or deletions. (Odd?)

  • The transaction itself includes a difference which in turn includes the removal and insertion changes of the dragged item. Nice!

Problem: The "Offset" included in the Insert change is strange. If I drag an item to the top of my section, the insertion offset is "5", which is unexpected.

What is this offset relative to? It does not seem relative to the section's children. Is the section transaction not intended to describe that?

Moving Rows Between Sections:

I'm getting similar results here. If I take an item form a lower section up to the first section I'll get an offset of "9". Despite expecting an offset of 1 relative to the destination section's top row (because the header is item 0).

I guess I'm mostly curious how I should be interpreting this transaction info. I'd prefer not to reconstitute my whole core-data store from the "final snapshot" that's available as part of the transaction.

Dropping the following into the didReorder block has helped me a little as I dive into this more. Pasting for future people in my position.

Code Block         reorderingHandlers.didReorder = { [weak self] transaction in
            print("++++++++++++")
            print("\(transaction.difference.count) TOP LEVEL DIFFERENCE CHANGES")
            transaction.difference.forEach { change in
                switch change {
                case .insert(let offset, let element, let associatedWith):
                    print("INSERT OFFSET: \(offset) ELEEMENT: \(element) associated: \(associatedWith)")
                case .remove(let offset, let element, let associatedWith):
                    print("REMOVE OFFSET: \(offset) ELEEMENT: \(element) associated: \(associatedWith)")
                }
            }
            
            print("------------------------------------------------------------")
            print("\(transaction.sectionTransactions.count) SECTION TRANSACTIONS")
            transaction.sectionTransactions.forEach { sectionTransaction in
                print("...........................................................")
                print("\(sectionTransaction.difference.count) DIFFERENCE CHANGES in \(sectionTransaction.sectionIdentifier)")
                sectionTransaction.difference.forEach { change in
                    switch change {
                    case .insert(let offset, let element, let associatedWith):
                        print("INSERT OFFSET: \(offset) ELEEMENT: \(element) associated: \(associatedWith)")
                    case .remove(let offset, let element, let associatedWith):
                        print("REMOVE OFFSET: \(offset) ELEEMENT: \(element) associated: \(associatedWith)")
                    }
                }
                print("...........................................................")
            }
            print("------------------------------------------------------------")
            print("++++++++++++")
}


Proper way to consume a reorder transaction?
 
 
Q