Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 24, 2024 01:34
Show Gist options
  • Select an option

  • Save takoikatakotako/5a1058551d2b1b4257ca5a8324fb909b to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/5a1058551d2b1b4257ca5a8324fb909b to your computer and use it in GitHub Desktop.
SwiftUIでリストを編集する
import SwiftUI
struct ContentView: View {
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
NavigationView {
List {
ForEach(users, id: \.self) { user in
Text(user)
}
.onDelete(perform: delete)
}
.navigationBarItems(trailing: EditButton())
}
}
func delete(at offsets: IndexSet) {
users.remove(atOffsets: offsets)
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment