2020-02-04a minute read (About 126 words)How to add drag and drop in SwiftUIIssue #594 12345678910111213141516171819202122232425262728293031323334353637383940414243444546struct SelectFileView: View { let buttonTitle: String @State var isDrop: Bool = false var body: some View { VStack(alignment: .leading) { Button(action: {}) { Text(buttonTitle) } .buttonStyle(ActionButtonStyle()) .offset(x: -16) Text("Alternatively, you can drag and drop file here") .font(.footnote) .foregroundColor(Color.gray) } .border(isDrop ? R.color.separator : Color.clear) .onDrop(of: [Constants.urlFileType], delegate: self) .padding(.bottom, 32) }}extension SelectFileView: DropDelegate { func dropEntered(info: DropInfo) { self.isDrop = true } func dropExited(info: DropInfo) { self.isDrop = false } func performDrop(info: DropInfo) -> Bool { guard let itemProvider = info.itemProviders(for: [Constants.urlFileType]).first else { return false } itemProvider.loadItem(forTypeIdentifier: Constants.urlFileType, options: nil) { item, error in guard let data = item as? Data, let url = URL(dataRepresentation: data, relativeTo: nil) else { return } } return true }} Updated at 2020-07-09 01:45:55 #swiftswiftUI