delete/add item

๐Ÿ“— ๅƒ่€ƒ๏ผšSwift Playgrounds (Keep Going with Apps) - Sharing Data Between Views.

struct ContentView: View {
    
    // inject data from environment
    @EnvironmentObject var data : CreatureZoo

    var body: some View {
        SPCAssessableGroup(view: self) {
            List {
                // ...
                
                // injected data
                ForEach(data.creatures) { creature in 
                    CreatureRow(creature: creature)
                }
                // โญ๏ธ action to delete data item ---------------
                .onDelete { indexSet in 
                    data.creatures.remove(atOffsets: indexSet)
                }
                // ---------------------------------------------
            }
        }
    }
}

Last updated