Home > AI > IOS > SwiftUI >

ForEach

Example 1:

 @State private var fruits = [
        "Apple",
        "Banana",
        "Papaya",
        "Mango"
    ]

    var body: some View {
        NavigationView{
            List {
                ForEach( fruits, id: \.self ) { fruit in
                    Text(fruit)
                }
                .onDelete { _ in print("delete")}
                .onMove { _,_ in print("move") }
            }
            .navigationTitle("Fruits")
            .toolbar { EditButton() }
        }
    }

Leave a Reply