title: List with drag and drop to reorder on SwiftUI
body: <p>How can I add drag and drop to reorder rows on SwiftUI?
  Just a clean solution without 'Edit mode'. <a href="https://iosexample.com/a-cells-of-uitableview-can-be-rearranged-by-drag-and-drop/" rel="noreferrer">Here</a> an example:</p>
  
  <p><a href="https://i.stack.imgur.com/Co4Xl.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/Co4Xl.gif" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I asked this question on <a href="https://swiftui-lab.com/drag-drop-with-swiftui/" rel="noreferrer">The SwiftUI Lab</a> and the author replied with this code. Only works on iPad</p>
  
  <pre class="lang-swift prettyprint-override"><code>    import SwiftUI
  
      struct Fruit: Identifiable {
          let id = UUID()
          let name: String
          let image: String
      }
              struct ContentView: View {
              @State var selection: Set&lt;UUID&gt; = []
  
              @State private var fruits = [
                  Fruit(name: "Apple", image: "apple"),
                  Fruit(name: "Banana", image: "banana"),
                  Fruit(name: "Grapes", image: "grapes"),
                  Fruit(name: "Peach", image: "peach"),
                  Fruit(name: "Kiwi", image: "kiwi"),
              ]
  
              var body: some View {
  
                  VStack {
                      NavigationView {
                          List(selection: $selection) {
                              ForEach(fruits) { fruit in
                                  HStack {
                                      Image(fruit.image)
                                          .resizable()
                                          .frame(width: 30, height: 30)
  
                                      Text(fruit.name)
                                  }
                              }
                              .onMove { _, _ in }
                          }
                          .navigationBarTitle("Fruits (Top)")
                      }
                  }
              }
          }
  </code></pre>