---
title: "decodeXPCObject(ofType:forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsxpccoder/decodexpcobject(oftype:forkey:)"
---

# decodeXPCObject(ofType:forKey:)

Decodes an object and validates that its type matches the type a service provides over XPC.

## Declaration

```swift
func decodeXPCObject(ofType type: xpc_type_t, forKey key: String) -> xpc_object_t?
```

## Parameters

- `type`: An opaque pointer to an encoded XPC object.
- `key`: A string that your app uses to reference the decoded object.

## Return Value

Return Value An object that XPC can encode.

## Discussion

Discussion The decodeXPCObject(ofType:forKey:) method validates that the type of the decoded object matches the type of the encoded object. If they don’t match, the NSXPCCoder throws an exception in support of NSSecureCoding. Be sure to check the result against null if you call an XPC function because calling an XPC function on a null object results in a crash.

## See Also

### Encoding and Decoding

- [encodeXPCObject(_:forKey:)](foundation/nsxpccoder/encodexpcobject(_:forkey:).md)
