Created
October 24, 2024 01:34
-
-
Save takoikatakotako/5a1058551d2b1b4257ca5a8324fb909b to your computer and use it in GitHub Desktop.
SwiftUIでリストを編集する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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