'CoreData @SectionedFetchRequest reversing a list with the same computed var Section Identifier

So I've got this simple list based app built with SwiftUI & CoreData which displays a list of current medicine a user is taking grouped into sections by @SectionedFetchRequest. The user can change the list to be grouped by first letter of medicine name, medicine type (tablet, capsule ect.) or by expiry date month. All these lists are reversible. The section identifier for expiry date grouping is a computed var which formats the date into a month based string. This works fine until I try to reverse the list while grouping by expiry date month and run into this crash/ error:

Thread 1: "UITableView internal inconsistency: encountered out of bounds global row index while preparing batch updates (oldRow=6, oldGlobalRowCount=6)"

I have found through some googling by following this tutorial that simply duplicating the computed var renaming it and appending + " " to the end of the return (see code below) then the app doesn't crash and allows the reversing of lists. This does however break the nice animation that CoreData gives by default when reversing the list. I'm not thrilled with the basically duplicating the code like this so was hoping there is another solution that doesn't involve duplicated code and doesn't break the animation?

Section Identifiers

@objc var scriptExpiryMonth: String {
    return Drug.formatter.string(from: scriptExpiry!)
}
//this works but animation breaks
@objc var scriptExpiryMonth2: String {
    return Drug.formatter.string(from: scriptExpiry!) + " "
}

Sort Tuple

//forward sort
(
    name: "Expiry Date",
    descriptors: [
        SortDescriptor(\Drug.scriptExpiry, order: .forward),
        SortDescriptor(\Drug.name, order: .forward),
        SortDescriptor(\Drug.dosage, order: .forward)
    ],
    section: \Drug.scriptExpiryMonth
), 
//reverse sort
(
    name: "Expiry Date",
    descriptors: [
        SortDescriptor(\Drug.scriptExpiry, order: .reverse),
        SortDescriptor(\Drug.name, order: .forward),
        SortDescriptor(\Drug.dosage, order: .forward)
    ],
    section: \Drug.scriptExpiryMonth2
)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source