<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSUserActivity/setTypedPayload(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:So14NSUserActivityC7SwiftUIE15setTypedPayloadyyxKSeRzSERzlF"
  },
  "title" : "setTypedPayload(_:)"
}
-->

# setTypedPayload(_:)

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

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

## Parameters

`payload`

The instance to convert to [`userInfo`](/documentation/Foundation/NSUserActivity/userInfo). The type of the `payload` instance must conform to <doc://com.apple.documentation/documentation/Swift/Codable>.

## Discussion

> Important:
> This method applies only to SwiftUI apps.

Use this method to set the user activity’s [`userInfo`](/documentation/Foundation/NSUserActivity/userInfo) dictionary in a type-safe manner. After you set the [`userInfo`](/documentation/Foundation/NSUserActivity/userInfo) dictionary using this approach, the keys in the [`userInfo`](/documentation/Foundation/NSUserActivity/userInfo) dictionary match the coding keys from the <doc://com.apple.documentation/documentation/Swift/Codable> type you provide as the `payload`.

If the type can’t be encoded into the [`userInfo`](/documentation/Foundation/NSUserActivity/userInfo) dictionary, this method throws [`NSUserActivity.TypedPayloadError.encodingError`](/documentation/Foundation/NSUserActivity/TypedPayloadError/encodingError).

---

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)