0

I use Simone´s solution to store string arrays and present them in a List:

How to Store Nested Arrays in @AppStorage for SwiftUI

I tried to add a row delete function to the List:

    .onDelete(perform: removeRows)
    
func removeRows(at offsets: IndexSet) {
        getStrings(data: albums).remove(atOffsets: offsets)
    }

I understand that this does not work because the function call returns an immutable value and I try to mutate it. How to resolve that?

RF2020
  • 15
  • 2

1 Answers1

0

Just add following delete function. You first get all string, then remove at offset and then store it back.

func removeRows(at offsets: IndexSet) {
    var tmpAlbums = getStrings(data: albums)
    tmpAlbums.remove(atOffsets: offsets)
    albums = Storage.archiveStringArray(object: tmpAlbums)
}
davidev
  • 7,694
  • 5
  • 21
  • 56