Forem

Saurabh Chavan
Saurabh Chavan

Posted on

1

Item delete & Move in SwiftUI

Swip to delete perticular item from the list we can achive using the onDelete() method

Also we can reorder the item using the onMove() metod

import SwiftUI

struct ContentView: View {
    @State private var Names = ["Saurabh","Sachin","Yuraj","Harbhajan","Rohit","Virat","Kapil","Dhoni"]
    var body: some View{
        NavigationView {
            VStack{
                List{
                    ForEach(Names,id: \.self) { name in
                        Text("\(name)")
                    }
                    .onDelete(perform: removeItem)
                    .onMove(perform: moveItem)
                }

            }
            .navigationTitle("Delete & Move")
            .toolbar {
                EditButton()
            }
        }
    }

    func removeItem(at offsets:IndexSet){
        Names.remove(atOffsets: offsets)
    }

    func moveItem(from source:IndexSet,to destination:Int){
        Names.move(fromOffsets: source, toOffset: destination)
    }
}




struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Enter fullscreen mode Exit fullscreen mode

outPut:

Image description

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay