<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/XPCDictionary",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "s:3XPC13XPCDictionaryV"
  },
  "title" : "XPCDictionary"
}
-->

# XPCDictionary

A type that contains key-value pairs, notably used as the container of messages between a client and listener.

```
struct XPCDictionary
```

## Topics

### Creating a dictionary

[`init()`](/documentation/XPC/XPCDictionary/init())

Creates an empty dictionary.

[`init(xpc_object_t)`](/documentation/XPC/XPCDictionary/init(_:))

Creates a dictionary using the keys and values in the specified object parameter.

[`func copy(into: XPCDictionary)`](/documentation/XPC/XPCDictionary/copy(into:))

Copies the keys and values of the dictionary to a different dictionary.

### Replying to client messages

[`func reply(XPCDictionary)`](/documentation/XPC/XPCDictionary/reply(_:))

Sends a reply to the originator of the dictionary.

### Inspecting a dictionary

[`var isEmpty: Bool`](/documentation/XPC/XPCDictionary/isEmpty)

A Boolean value that indicates whether the dictionary is empty.

[`var count: Int`](/documentation/XPC/XPCDictionary/count)

The number of key-value pairs in the dictionary.

### Accessing keys and values

[`var keys: [String]`](/documentation/XPC/XPCDictionary/keys)

A collection containing just the keys of the dictionary.

[`var values: [xpc_object_t]`](/documentation/XPC/XPCDictionary/values)

A collection containing just the values of the dictionary.

[`subscript(String) -> XPCDictionary?`](/documentation/XPC/XPCDictionary/subscript(_:)-4hbmg)

Reads and writes the value associated with the given key as an XPC dictionary.

[`subscript(String) -> String?`](/documentation/XPC/XPCDictionary/subscript(_:)-80fs2)

Reads and writes the value associated with the given key as a string.

[`subscript(String) -> Bool?`](/documentation/XPC/XPCDictionary/subscript(_:)-gas6)

Reads and writes the value associated with the given key as a Boolean value.

[`subscript(String) -> xpc_object_t?`](/documentation/XPC/XPCDictionary/subscript(_:)-4j21u)

Reads and writes the value associated with the given key as an XPC object.

[`subscript<T>(String) -> T?`](/documentation/XPC/XPCDictionary/subscript(_:)-8gyze)

Reads and writes the value associated with the given key as a floating point value.

[`subscript<T>(String) -> T?`](/documentation/XPC/XPCDictionary/subscript(_:)-4vrsa)

Reads and writes the value associated with the given key as an unsigned integer value.

[`subscript<T>(String) -> T?`](/documentation/XPC/XPCDictionary/subscript(_:)-3i01t)

Reads and writes the value associated with the given key as a signed integer value.

[`subscript(String, as _: XPCDictionary.Type) -> XPCDictionary?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-1mm7n)

Reads the value associated with the given key as an XPC dictionary.

[`subscript(String, as _: String.Type) -> String?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-4zxc8)

Reads and writes the value associated with the given key as a string.

[`subscript(String, as _: Bool.Type) -> Bool?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-18db5)

Reads and writes the value associated with the given key as a Boolean value.

[`subscript(String, as _: any OS_xpc_object.Type) -> xpc_object_t?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-5y39v)

Reads and writes the value associated with the given key as an XPC object.

[`subscript(String, as _: xpc_type_t) -> xpc_object_t?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-qjxa)

Reads and writes the value associated with the given key as an XPC object.

[`subscript<T>(String, as _: T.Type) -> T?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-3mzgc)

Reads and writes the value associated with the given key as a floating point value.

[`subscript<T>(String, as _: T.Type) -> T?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-119cl)

Reads and writes the value associated with the given key as an integer value.

[`subscript(String, as _: Bool.Type, default _: @autoclosure () -> Bool) -> Bool`](/documentation/XPC/XPCDictionary/subscript(_:as:default:)-5ufgs)

Reads and writes the value associated with the given key as a Boolean value, falling back to the given default value.

[`subscript<T>(String, as _: T.Type, default _: @autoclosure () -> T) -> T`](/documentation/XPC/XPCDictionary/subscript(_:as:default:)-4ssx3)

Reads and writes the value associated with the given key converted to the specified type, falling back to the given default value.

[`func withUnsafeUnderlyingDictionary<ReturnType>((xpc_object_t) throws -> ReturnType) rethrows -> ReturnType`](/documentation/XPC/XPCDictionary/withUnsafeUnderlyingDictionary(_:))

Calls a closure with an unsafe reference to the dictionary.

### Removing keys and values

[`func removeValue(forKey: String) -> xpc_object_t?`](/documentation/XPC/XPCDictionary/removeValue(forKey:))

Removes the given key and its associated value from the dictionary.

### Supporting types

[`typealias KeyValuePair`](/documentation/XPC/XPCDictionary/KeyValuePair)

A type that contains a dictionary’s key-value pair.

### Iterating over keys and values

[`func forEach((XPCDictionary.KeyValuePair) throws -> Void) rethrows`](/documentation/XPC/XPCDictionary/forEach(_:)-9hufx)

Calls the given closure with each element in the dictionary in the same order as a for-in loop.

[`func forEach((String, xpc_object_t) throws -> Void) rethrows`](/documentation/XPC/XPCDictionary/forEach(_:)-6riqn)

Calls the given closure with each key and value in the dictionary in the same order as a for-in loop.

### Transforming a dictionary

[`func map<ReturnType>((XPCDictionary.KeyValuePair) throws -> ReturnType) rethrows -> [ReturnType]`](/documentation/XPC/XPCDictionary/map(_:))

Returns an array containing the results of mapping the given closure over the sequence’s elements.

### Subscripts

[`subscript(String) -> uuid_t?`](/documentation/XPC/XPCDictionary/subscript(_:)-11qvo)

Get or set a value in this dictionary as a UUID.

[`subscript(String) -> XPCEndpoint?`](/documentation/XPC/XPCDictionary/subscript(_:)-2p7tp)

Get or set an `XPCEndpoint` value in this dictionary.

[`subscript(String) -> FileDescriptor?`](/documentation/XPC/XPCDictionary/subscript(_:)-hl1w)

Get or set a value in this dictionary as a file descriptor.

[`subscript(String) -> RawSpan?`](/documentation/XPC/XPCDictionary/subscript(_:)-n49r)

Get or set a value in this dictionary as data.

[`subscript(String) -> XPCArray?`](/documentation/XPC/XPCDictionary/subscript(_:)-u6bo)

Get or set a value in this dictionary as an XPCArray.

[`subscript(String, as _: RawSpan.Type) -> RawSpan?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-1nvet)

Get a value in this dictionary as data.

[`subscript(String, as _: FileDescriptor.Type) -> FileDescriptor?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-279le)

Get a value in this dictionary as a file descriptor.

[`subscript(String, as _: XPCArray.Type) -> XPCArray?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-58a41)

Get a value in this dictionary as an XPCArray.

[`subscript(String, as _: XPCEndpoint.Type) -> XPCEndpoint?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-7rdzi)

Get an `XPCEndpoint` value in this dictionary.

[`subscript(String, as _: uuid_t.Type) -> uuid_t?`](/documentation/XPC/XPCDictionary/subscript(_:as:)-91g9b)

Get a value in this dictionary as a UUID.

[`subscript(String, as _: XPCArray.Type, default _: @autoclosure () -> XPCArray) -> XPCArray`](/documentation/XPC/XPCDictionary/subscript(_:as:default:)-17z80)

Get a value in this dictionary as an XPCArray.

[`subscript(String, as _: FileDescriptor.Type, default _: @autoclosure () -> FileDescriptor) -> FileDescriptor`](/documentation/XPC/XPCDictionary/subscript(_:as:default:)-51ffh)

Get a value in this dictionary as a file descriptor.

[`subscript(String, as _: uuid_t.Type, default _: @autoclosure () -> uuid_t) -> uuid_t`](/documentation/XPC/XPCDictionary/subscript(_:as:default:)-vwea)

Get a value in this dictionary as a UUID.

### Default Implementations

[ExpressibleByDictionaryLiteral Implementations](/documentation/XPC/XPCDictionary/ExpressibleByDictionaryLiteral-Implementations)

## Relationships

### Conforms To

[`ExpressibleByDictionaryLiteral`](/documentation/Swift/ExpressibleByDictionaryLiteral)

[`Hashable`](/documentation/Swift/Hashable)

[`Escapable`](/documentation/Swift/Escapable)

[`Equatable`](/documentation/Swift/Equatable)

[`Copyable`](/documentation/Swift/Copyable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)