skip to content

In a SwiftUI mood-board app, cards drag between its own screens, but dropping one into Notes does nothing and text dragged from Notes never lands; why?

level: seniorimportance: should knowfreq 35%

answer

  1. what the receiver can read
  2. one representation, one private type
  3. an export-only fallback
  4. Info.plist conformance to public.data
  5. list the exported and imported types

basics

~20 s

Notes can't read the card's custom content type and no common fallback is offered; text can't become a card because nothing imports String. Add a two-way ProxyRepresentation to String, and declare the custom type in Info.plist conforming to public.data.

solid answer

~40 s

Inside the app, both ends speak `com.example.moodboard.card`, so the `CodableRepresentation` carries the whole card. Notes doesn't understand that type, and with no other representation it is offered nothing it can accept. The reverse fails for a mirrored reason: `dropDestination(for: MoodCard.self)` can only build cards through the card's import representations, and none imports plain text. Adding `ProxyRepresentation(exporting: \.caption)` fixes only the first symptom, because it is export-only. The fix is a `ProxyRepresentation` with both closures, listed after the custom type, so Notes receives the caption and dropped text becomes a new card. Also confirm the custom type is declared under `UTExportedTypeDeclarations` conforming to `public.data`, and that no `.visibility(.ownProcess)` hides the fallback. On iOS 18.2 and later, `MoodCard.exportedContentTypes()` and `importedContentTypes()` show exactly what the type offers and accepts.

code

swift · 28 lines
swift
import SwiftUI
import UniformTypeIdentifiers

extension UTType {
    // Mirrors the UTExportedTypeDeclarations entry in Info.plist,
    // which declares conformance to public.data.
    static let moodCard = UTType(exportedAs: "com.example.moodboard.card")
}

struct MoodCard: Codable, Transferable {
    var caption: String

    static var transferRepresentation: some TransferRepresentation {
        CodableRepresentation(contentType: .moodCard)
        // Was ProxyRepresentation(exporting: \.caption): export-only.
        ProxyRepresentation { card in
            card.caption
        } importing: { text in
            MoodCard(caption: text)
        }
    }
}

@available(iOS 18.2, *)
func logCardTypes() {
    print("exports:", MoodCard.exportedContentTypes().map(\.identifier))
    print("imports:", MoodCard.importedContentTypes().map(\.identifier))
}

go deeper

for a junior

Recall that another app can only accept a format it understands, so a private custom type needs a common fallback such as text.

for a middle

Explain export versus import: an exporting-only proxy sends text out but cannot turn incoming text into a card.

for a senior

Diagnose systematically: list exported and imported types, check direction, visibility, exporting conditions and the Info.plist declaration, then lock the result in with a test.

for a principal

Decide which interoperability the product guarantees, which apps and formats you test against, and who owns the custom type's declaration as it evolves.

## Why it works inside the app Drag and drop between two places in the same app succeeds because **both ends agree on the custom content type**. The card conforms to `Transferable` with `CodableRepresentation(contentType: .moodCard)`, where `.moodCard` is `UTType(exportedAs: "com.example.moodboard.card")`. The source exports JSON under that identifier and the destination, `dropDestination(for: MoodCard.self)`, imports it. None of that shows other apps can take part. ## Why Notes ignores the card A receiver can only accept content in a type it understands. Notes has never heard of `com.example.moodboard.card`, so if that is the conformance's only representation, the drag offers Notes nothing it can read. Apple's guidance is to follow the most faithful representation with **more compatible but less preferable** ones, and its own samples add a `ProxyRepresentation` to `String` for exactly this reason: so the item can be dropped into a text editor that doesn't support the custom type. ## Why text from Notes never lands The reverse direction has its own cause. `dropDestination(for: MoodCard.self)` produces `MoodCard` values through the card's **import** representations, and a custom-type `CodableRepresentation` imports only that custom type. A drag carrying plain text therefore matches nothing the board can build. The common half-fix makes this easy to miss: adding `ProxyRepresentation(exporting: \.caption)` lets Notes receive the caption, but it only exports, so it still gives the card no way to be created from a `String`. Apple's contact sample shows the remedy: a `ProxyRepresentation` with an `importing:` closure that creates a contact from the dropped string. ## A diagnosis checklist 1. **List what the type offers.** On iOS 18.2 and later, `MoodCard.exportedContentTypes()` and `MoodCard.importedContentTypes()` return the `UTType`s the conformance exports and imports; print them or assert them in a unit test. 2. **Look for a compatible fallback.** Is there a representation whose type other apps understand, such as text, an image or a vCard? 3. **Check its direction.** Does the fallback have an importing closure, or was it built with `exporting:` or `exportedContentType:` only? 4. **Check visibility.** A `.visibility(.ownProcess)` or `.team` modifier hides a representation from apps outside that scope. 5. **Check exporting conditions.** An `exportingCondition(_:)` that returns `false` for a card suppresses that representation for it. 6. **Check the declaration.** Apple's documentation tells you to include an Info.plist entry for every custom type identifier you declare; under Exported Type Identifiers (`UTExportedTypeDeclarations`) the type should conform to `public.data` or `com.apple.package` so the system understands how to handle the content. ## The fixed conformance | Conformance | Notes receives | The board accepts from Notes | |---|---|---| | `CodableRepresentation(contentType: .moodCard)` alone | nothing | nothing | | plus `ProxyRepresentation(exporting: \.caption)` | the caption | nothing | | plus a `ProxyRepresentation` with exporting and importing closures | the caption | a new card built from the text | The Info.plist declaration for the custom type looks like this: ```xml <key>UTExportedTypeDeclarations</key> <array> <dict> <key>UTTypeIdentifier</key> <string>com.example.moodboard.card</string> <key>UTTypeConformsTo</key> <array> <string>public.data</string> </array> </dict> </array> ``` ## Reproducing it Cross-app drops are easiest to test on iPad with a second app beside yours in Split View, which is how Apple suggests trying its drag-and-drop sample with Contacts or Notes: - drag a card from the board into a note and check what arrives; - drag a line of text from the note onto the board and check that a card appears; - drag a card between two screens of your own app to confirm the full-fidelity path still wins; - on iOS 18.2 or later, log `exportedContentTypes()` and `importedContentTypes()` to see the lists the system works from. ## What not to change - **Reordering.** Moving the proxy above the custom type adds no import path; it only makes plain text the preferred format, so even receivers that understand the card might get text. - **Going generic.** Registering the card as `UTType.data` doesn't make it readable anywhere; Apple advises a content type that describes the data. - **Importing your own type.** `UTImportedTypeDeclarations` registers a type another app defines, not one your app owns. - **Adding hover feedback.** An `isTargeted` closure reports hovering; it never changes which content the board can import.

  • Would a FileRepresentation also help the card reach Notes?
    For sharing it can: Apple's ShareLink documentation says some apps, Notes among them, offer their sharing service for files rather than for a wide range of data types. For dropping a caption into a note, the two-way `String` proxy is the direct fix; a file representation earns its place when the card has a real file form, such as an exported image.
  • How would you keep this from regressing?
    On iOS 18.2 and later, a unit test can assert that `MoodCard.exportedContentTypes()` contains the custom type and a text type, and that `importedContentTypes()` includes text. Deleting the fallback or its importing closure then fails the test instead of surfacing as a silent drop failure in another app.

  • If dragging works inside the app, it will work with any other app.
  • Moving the String proxy to the top makes text drops create cards.
  • ProxyRepresentation(exporting:) lets the type import text as well.
  • Declaring the app's own type under UTImportedTypeDeclarations fixes cross-app drops.
  • Registering the card as UTType.data lets every app read it.