<!--
{
  "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/XPCArray",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "s:3XPC8XPCArrayV"
  },
  "title" : "XPCArray"
}
-->

# XPCArray

An ordered random-access collection of XPC objects.

```
struct XPCArray
```

## Topics

### Creating an array

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

Creates a new, empty array.

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

Creates a new array that contains the given XPC object.

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

Copies the elements of the array to a different array.

### Inspecting an array

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

A Boolean value that indicates whether the array is empty.

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

The number of elements in the array.

### Accessing elements

[`subscript(Int) -> XPCDictionary?`](/documentation/XPC/XPCArray/subscript(_:)-1s7qq)

Reads and writes the value at the given index as an XPC dictionary.

[`subscript(Int) -> String?`](/documentation/XPC/XPCArray/subscript(_:)-6c9gh)

Reads and writes the value at the given index as a string.

[`subscript(Int) -> Bool?`](/documentation/XPC/XPCArray/subscript(_:)-i6v5)

Reads and writes the value at the given index as a Boolean value.

[`subscript(Int) -> xpc_object_t?`](/documentation/XPC/XPCArray/subscript(_:)-56wjj)

Reads and writes the value at the given index as an XPC object.

[`subscript<T>(Int) -> T?`](/documentation/XPC/XPCArray/subscript(_:)-8wubg)

Reads and writes the value at the given index as a floating point value.

[`subscript<T>(Int) -> T?`](/documentation/XPC/XPCArray/subscript(_:)-9x9ho)

Reads and writes the value at the given index as an unsigned integer.

[`subscript<T>(Int) -> T?`](/documentation/XPC/XPCArray/subscript(_:)-2f94n)

Reads and writes the value at the given index as a signed integer.

[`subscript(Int, as _: XPCDictionary.Type) -> XPCDictionary?`](/documentation/XPC/XPCArray/subscript(_:as:)-3ae6x)

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

[`subscript(Int, as _: String.Type) -> String?`](/documentation/XPC/XPCArray/subscript(_:as:)-9ukjj)

Reads and writes the value at the given index as a string.

[`subscript(Int, as _: Bool.Type) -> Bool?`](/documentation/XPC/XPCArray/subscript(_:as:)-1bilh)

Reads and writes the value at the given index as a Boolean value.

[`subscript(Int, as _: any OS_xpc_object.Type) -> xpc_object_t?`](/documentation/XPC/XPCArray/subscript(_:as:)-931lh)

Reads and writes the value at the given index as an XPC object.

[`subscript(Int, as _: xpc_type_t) -> xpc_object_t?`](/documentation/XPC/XPCArray/subscript(_:as:)-3tgp4)

Reads and writes the value at the given index as an XPC object.

[`subscript<T>(Int, as _: T.Type) -> T?`](/documentation/XPC/XPCArray/subscript(_:as:)-2hql9)

Reads and writes the value at the given index as a floating point value.

[`subscript<T>(Int, as _: T.Type) -> T?`](/documentation/XPC/XPCArray/subscript(_:as:)-6grs4)

Reads and writes the value at the given index as an integer value.

[`subscript(Int, as _: Bool.Type, default _: @autoclosure () -> Bool) -> Bool`](/documentation/XPC/XPCArray/subscript(_:as:default:)-2bn95)

Reads and writes the value at the given index as a Boolean value, falling back to the given default value.

[`subscript<T>(Int, as _: T.Type, default _: @autoclosure () -> T) -> T`](/documentation/XPC/XPCArray/subscript(_:as:default:)-3k2qm)

Reads and writes the value at the given index as a floating point value, falling back to the given default value.

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

Calls a closure with an unsafe reference to the array.

### Iterating over an array’s elements

[`func forEach((XPCArray.IndexValuePair) throws -> Void) rethrows`](/documentation/XPC/XPCArray/forEach(_:)-6obs3)

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

[`func forEach((Int, xpc_object_t) throws -> Void) rethrows`](/documentation/XPC/XPCArray/forEach(_:)-2ib8a)

Calls the given closure with an index and element of the array in the same order as a for-in loop.

### Transforming an array

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

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

### Supporting types

[`typealias IndexValuePair`](/documentation/XPC/XPCArray/IndexValuePair)

A type that contains an index and the object at that index.

### Subscripts

[`subscript(Int) -> XPCArray?`](/documentation/XPC/XPCArray/subscript(_:)-6ud0q)

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

[`subscript(Int) -> XPCEndpoint?`](/documentation/XPC/XPCArray/subscript(_:)-7io5d)

Get or set a value in this array as an endpoint.

[`subscript(Int) -> uuid_t?`](/documentation/XPC/XPCArray/subscript(_:)-9akd5)

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

[`subscript(Int) -> FileDescriptor?`](/documentation/XPC/XPCArray/subscript(_:)-9c21w)

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

[`subscript(Int) -> RawSpan?`](/documentation/XPC/XPCArray/subscript(_:)-us15)

Get or set a value in this array as data.

[`subscript(Int, as _: uuid_t.Type) -> uuid_t?`](/documentation/XPC/XPCArray/subscript(_:as:)-4xkvt)

Get a value in this array as a UUID.

[`subscript(Int, as _: FileDescriptor.Type) -> FileDescriptor?`](/documentation/XPC/XPCArray/subscript(_:as:)-54977)

Get a value in this array as a file descriptor.

[`subscript(Int, as _: XPCEndpoint.Type) -> XPCEndpoint?`](/documentation/XPC/XPCArray/subscript(_:as:)-5g1u8)

Get a value in this array as an endpoint.

[`subscript(Int, as _: XPCArray.Type) -> XPCArray?`](/documentation/XPC/XPCArray/subscript(_:as:)-6vjz)

Get a value in this array as an XPCArray.

[`subscript(Int, as _: RawSpan.Type) -> RawSpan?`](/documentation/XPC/XPCArray/subscript(_:as:)-96zf2)

Get a value in this array as data.

[`subscript(Int, as _: FileDescriptor.Type, default _: @autoclosure () -> FileDescriptor) -> FileDescriptor`](/documentation/XPC/XPCArray/subscript(_:as:default:)-3h2ng)

Get a value in this array as a file descriptor.

[`subscript(Int, as _: XPCEndpoint.Type, default _: @autoclosure () -> XPCEndpoint) -> XPCEndpoint`](/documentation/XPC/XPCArray/subscript(_:as:default:)-46zsb)

Get a value in this array as an endpoint.

[`subscript(Int, as _: uuid_t.Type, default _: @autoclosure () -> uuid_t) -> uuid_t`](/documentation/XPC/XPCArray/subscript(_:as:default:)-4ey7n)

Get a value in this array as a UUID.

[`subscript(Int, as _: XPCArray.Type, default _: @autoclosure () -> XPCArray) -> XPCArray`](/documentation/XPC/XPCArray/subscript(_:as:default:)-645o4)

Get a value in this array as an XPCArray.

## Relationships

### Conforms To

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

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

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

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

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

---

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)