---
title: "userActivity(_:element:_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/useractivity(_:element:_:)"
---

# userActivity(_:element:_:)

Advertises a user activity type.

## Declaration

```swift
nonisolated func userActivity<P>(_ activityType: String, element: P?, _ update: @escaping (P, NSUserActivity) -> ()) -> some View

```

## Parameters

- `activityType`: The type of activity to advertise.
- `element`: If the element is nil, the handler will not be associated with the activity (and if there are no handlers, no activity is advertised). The method passes the non-nil element to the handler as a convenience so the handlers don’t all need to implement an early exit with guard element = element else { return }.
- `update`: A function that modifies the passed-in activity for advertisement.

## Discussion

Discussion The scope of the activity applies only to the scene or window the view is in.

## See Also

### Sending and receiving user activities

- [Restoring your app’s state with SwiftUI](swiftui/restoring-your-app-s-state-with-swiftui.md)
- [userActivity(_:isActive:_:)](swiftui/view/useractivity(_:isactive:_:).md)
- [onContinueUserActivity(_:perform:)](swiftui/view/oncontinueuseractivity(_:perform:).md)
