---
title: "encodeXPCObject(_:forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsxpccoder/encodexpcobject(_:forkey:)"
---

# encodeXPCObject(_:forKey:)

Encodes an object to send over an XPC connection.

## Declaration

```swift
func encodeXPCObject(_ xpcObject: xpc_object_t, forKey key: String)
```

## Parameters

- `xpcObject`: An object that XPC can encode.
- `key`: A string that your app uses to reference the encoded object.

## See Also

### Encoding and Decoding

- [decodeXPCObject(ofType:forKey:)](foundation/nsxpccoder/decodexpcobject(oftype:forkey:).md)
