Member-only story

First Experience With Transferable Implementing Drag And Drop In SwiftUI

A game changer protocol in Swift

Gabriel Theodoropoulos
11 min readJul 21, 2022
Photo by Karolina Grabowska: https://www.pexels.com/photo/orange-usb-charger-cable-on-black-surface-4219862/

In WWDC 2022 and among other interesting announcements, Apple presented a new protocol in Swift, named Transferable. In a nutshell, Transferable makes it really easy and absolutely straightforward to copy data either among different spots within the same app, or even different apps. And when talking about copy, this does not include only copy and paste, but drag and drop as well.

Before Transferable became available, it had been necessary to perform a series of certain steps in order to transfer data as mentioned above. For custom types especially, it had been mandatory to adopt specific protocols and implement some required methods in order to serialize and deserialize, work with item providers and their contained data, and more. However, all related details are not of much interest here, as the topic is the evolution of all that, the Transferable protocol. For someone that has worked with all that, Transferable is definitely a game changer.

With Transferable it takes really little to no effort to copy or drag and drop the following:

  • Objects of custom types that conform to Codable protocol
  • Data
  • Files

--

--

Gabriel Theodoropoulos
Gabriel Theodoropoulos

Written by Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev

No responses yet