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.
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, wherenilrepresents the no-connection state and a non-nilvalue means a specific remote device is bound to this view's lifetime.Branch on presence to drive your UI
Since
RemoteDeviceIdentifier?carries presence in its optionality, a simplenilcheck is enough to decide what to show. Heredevice == nil ? "No device connected" : "Connected"reads the optional directly, switching the statusTextbased on whether an identifier is currently held.Treat the identifier as an opaque, comparable identity
RemoteDeviceIdentifieris 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.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
RemoteDeviceIdentifierDemoview, with itslaptopcomputer.and.iphoneimage, stands in for that cross-device context where the identifier would be supplied to your scene.
@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.
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()
}
}