title: SwiftUI | Using onDrag and onDrop to reorder Items within one single LazyGrid?
body: <p>I was wondering if it is possible to use the <code>View.onDrag</code> and <code>View.onDrop</code> to add drag and drop reordering within one <code>LazyGrid</code> manually?</p>
  <p>Though I was able to make every Item draggable using <code>onDrag</code>, I have no idea how to implement the dropping part.</p>
  <img src="https://i.stack.imgur.com/PqvP8.gif" width="200" />
  <p>Here is the code I was experimenting with:</p>
  <pre><code>import SwiftUI
  
  //MARK: - Data
  
  struct Data: Identifiable {
      let id: Int
  }
  
  //MARK: - Model
  
  class Model: ObservableObject {
      @Published var data: [Data]
      
      let columns = [
          GridItem(.fixed(160)),
          GridItem(.fixed(160))
      ]
      
      init() {
          data = Array&lt;Data&gt;(repeating: Data(id: 0), count: 100)
          for i in 0..&lt;data.count {
              data[i] = Data(id: i)
          }
      }
  }
  
  //MARK: - Grid
  
  struct ContentView: View {
      @StateObject private var model = Model()
      
      var body: some View {
          ScrollView {
              LazyVGrid(columns: model.columns, spacing: 32) {
                  ForEach(model.data) { d in
                      ItemView(d: d)
                          .id(d.id)
                          .frame(width: 160, height: 240)
                          .background(Color.green)
                          .onDrag { return NSItemProvider(object: String(d.id) as NSString) }
                  }
              }
          }
      }
  }
  
  //MARK: - GridItem
  
  struct ItemView: View {
      var d: Data
      
      var body: some View {
          VStack {
              Text(String(d.id))
                  .font(.headline)
                  .foregroundColor(.white)
          }
      }
  }
  </code></pre>
  <p>Thank you!</p>