Saturday, April 6, 2024
HomeiOS Developmentios - Deleting merchandise of sorted information in a ForEach

ios – Deleting merchandise of sorted information in a ForEach


I’ve a ForEach that I take advantage of to show some information, sorted on it is date attribute:

My view appears like:

ForEach(information.sorted(by: < ), id: .self) { report in
                Textual content("(report.date")
            }
            .onDelete(carry out: deleteRecord)

File.swift

class File : Comparable {
    
    var worth: Float
    var date: Date
    
    
    init(worth: Float = 0.0, date: Date = Date.now) {
        self.worth = worth
        self.date = date
    }
    
    static func < (lhs: File, rhs: File) -> Bool {
        return lhs.date < rhs.date
    }
    
}

My downside is that each time I delete an merchandise, the unsuitable one is definitely eliminated.

deleteRecord()

func deleteRecord(_ indexSet: IndexSet) {
        for index in indexSet {
            motion.information.take away(at: index)
        }
    }

I’v tried altering the deleteRecord() technique to one thing like:

func deleteRecord(at offsets: IndexSet) {
        motion.information.take away(atOffsets: offsets)
    }

however this didn’t solved my situation.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments