TechnologiesSwiftUIScenes and Windows

RemoteDeviceIdentifier struct

iOSmacOStvOSwatchOSvisionOS✓ renders

An opaque type that identifies a remote device displaying scene content

How it works

RemoteDeviceIdentifier is a structure that names a single remote device taking part in an interaction with your app, such as a companion phone driving a session on another screen. SwiftUI hands you a value of this type so you can tell participating devices apart, track which one a piece of state belongs to, and key your own bookkeeping to a stable identity rather than a transient connection. Reach for it whenever a scene spans more than one device and you need to recognize, store, or compare the device on the far end of the link.

  1. Hold an identifier with an optional property

    Because a remote device may or may not be present, you typically model it as an optional. The example keeps @State private var device: RemoteDeviceIdentifier? = nil, where nil represents the no-connection state and a non-nil value means a specific remote device is bound to this view's lifetime.

  2. Branch on presence to drive your UI

    Since RemoteDeviceIdentifier? carries presence in its optionality, a simple nil check is enough to decide what to show. Here device == nil ? "No device connected" : "Connected" reads the optional directly, switching the status Text based on whether an identifier is currently held.

  3. Treat the identifier as an opaque, comparable identity

    RemoteDeviceIdentifier is meant to be used as a handle, not inspected for its internal makeup. You compare two values to confirm you are talking to the same device across events, and you store the value to associate per-device state with the participant it came from, rather than parsing or constructing one yourself.

  4. Scope it to a multi-device scene

    The type belongs to the Scenes and Windows domain because it identifies a participant in an interaction that reaches beyond a single device. The surrounding RemoteDeviceIdentifierDemo view, with its laptopcomputer.and.iphone image, stands in for that cross-device context where the identifier would be supplied to your scene.

Try it — Seed the property with a value by changing @State private var device: RemoteDeviceIdentifier? = nil to start from a connected identifier, and watch the status Text flip from "No device connected" to "Connected".

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

RemoteDeviceIdentifier.swift
struct RemoteDeviceIdentifierDemo: View {
    @State private var device: RemoteDeviceIdentifier? = nil

    var body: some View {
        VStack(spacing: 12) {
            Image(systemName: "laptopcomputer.and.iphone")
                .font(.largeTitle)
                .foregroundStyle(.tint)
            Text("Remote Device")
                .font(.headline)
            Text(device == nil ? "No device connected" : "Connected")
                .font(.subheadline)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
Remote Device No device connected
Remote Device No device connected
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →