From the course: iPadOS 13 Development Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Implementing simple drag and drop - iOS Tutorial
From the course: iPadOS 13 Development Essential Training
Implementing simple drag and drop
- [Instructor] Now let's look at using SwiftUI to implement drag and drop in multiple windows with the same application. So here I'm creating an image that's a state variable. And then I'm using the image in my body and then I have this method for handling when we drop the image. So what we need to do is we need to handle dragging the image first and we need to say that when we drag, we're sending the image data. So we call onDrag and I'm going to press Return to have it autocomplete that for me and I'm going to return NSItemProvider, so I'll make a new instance and the object is going to be self.myImage. So if we wanted to simplify this, since we're not using our ItemProvider, we can just delete this code. And then put it on one line like that. On the next line, let's implement onDrop. So first, we need to specify an array of strings that are the types of items that our image can accept as a drop. So that's…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.