跳转至
Structure

DropInfo

The current state of a drop.

Declaration

struct DropInfo

Overview

struct ExampleView: View {
    @State var text: String = "🍌🍌"

    var body: some View {
        HStack {
            // Text to drag
            Text(text)
                .font(.title)
                .onDrag { NSItemProvider(object: self.text as NSString) }

            // Area to drop
            RoundedRectangle(cornerRadius: 10)
                .frame(width: 150, height: 150)
                .onDrop(of: ["text"], delegate: MyDropDelegate(text: $text))
        }
    }
}

struct MyDropDelegate: DropDelegate {
    @Binding var text: String

    func performDrop(info: DropInfo) -> Bool {
        self.text = "Dropped My Bananas 🍌🍌!"
        return true
    }
}
A gif displaying a view containing an HStack with two components, a text view "🍌🍌", derived from a state variable, and a rounded rectangle with an onDrop condition; once the text is dragged into the rectangle, onDrop is triggered and the text object is switched out with another reading "Dropped My Bananas 🍌🍌!"

Availability

iOS 13.4+

macOS 10.15+

Topics


Instance Method

hasItemsConforming(to:) Returns whether at least one item conforms to at least one of the specified uniform type identifiers.

hasItemsConforming(to:) Indicates whether at least one item conforms to at least one of the specified uniform type identifiers.

itemProviders(for:) Returns an Array of items that each conform to at least one of the specified uniform type identifiers.

itemProviders(for:) Finds item providers that conform to at least one of the specified uniform type identifiers.


Instance Property

location The location of the drag in the coordinate space of the drop view.