Skip to content

Instantly share code, notes, and snippets.

@CastIrony
Created July 27, 2020 18:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save CastIrony/39831c7d0c711c1bf2e319b704d6312f to your computer and use it in GitHub Desktop.
import SwiftUI
struct ListTestView: View {
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
NavigationView {
List {
ForEach(users, id: \.self) { user in
Text(user)
}
.onMove(perform: move)
}
.navigationBarItems(trailing: EditButton())
}
}
func move(from source: IndexSet, to destination: Int) {
users.move(fromOffsets: source, toOffset: destination)
}
}
struct ListTestView_Previews: PreviewProvider {
static var previews: some View {
ListTestView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment