|
I'm stuck on how to delete when there are sections present in the list of expenses. First I created the two sections using .filter to filter based on Personal vs Business.
This doesn't work. It deletes the wrong row. Then I thought I could create two removeItems functions, one called removePersonalItems and one called removeBusinessItems. I then modified the functions as follows:
But this fails as .filter returns an immutable array. Then I thought maybe I could delete by ID, since ExpenseItem conforms to Identifiable but I can find no way to do so. onDelete doesn't seem to capture the id of the item. Then I thought maybe there's something I can do with an IndexSet, some method or property that would be of use. But without being able to see what is being sent to removeItems, it's difficult to figure out. So I figured I'd print the offsets parameter to the console, but using print(offsets) in removeItems does nothing. Nothing is displayed on the console at all. So what's the solution? |
|
|
|
I didn't use It seems to delete the correct items every time this way. But I remember thinking that it was strange that I didn't have to do anything special to make sure that the proper items were deleted, since Paul specifically mentions that we have to be careful about how we delete the items.
It's still just using
|
|
When you use .filter it returns a NEW array, thus the onDelete using the below
will not work. Making separate arrays will work, but is it worth it? Unless there is a way to modify the removeItems method..tried a bit with no much success |
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.