---
title: "setTypedPayload(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsuseractivity/settypedpayload(_:)"
---

# setTypedPayload(_:)

Encodes the specified payload into the user activity’s user info dictionary.

## Declaration

```swift
func setTypedPayload<T>(_ payload: T) throws where T : Decodable, T : Encodable
```

## Parameters

- `payload`: The instance to convert to doc://com.apple.foundation/documentation/Foundation/NSUserActivity/userInfo. The type of the payload instance must conform to doc://com.apple.documentation/documentation/Swift/Codable.

## Discussion

Discussion important: This method applies only to SwiftUI apps. Use this method to set the user activity’s userInfo dictionary in a type-safe manner. After you set the userInfo dictionary using this approach, the keys in the userInfo dictionary match the coding keys from the Codable type you provide as the payload. If the type can’t be encoded into the userInfo dictionary, this method throws NSUserActivity.TypedPayloadError.encodingError.

## See Also

### Managing type-safe access to user info

- [typedPayload(_:)](foundation/nsuseractivity/typedpayload(_:).md)
- [NSUserActivity.TypedPayloadError](foundation/nsuseractivity/typedpayloaderror.md)
