<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/userActivity",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(py)userActivity"
  },
  "title" : "userActivity"
}
-->

# userActivity

An object that encapsulates a user activity the document supports.

```
var userActivity: NSUserActivity? { get set }
```

## Discussion

[`NSDocument`](/documentation/AppKit/NSDocument) automatically creates <doc://com.apple.documentation/documentation/Foundation/NSUserActivity> objects. The system makes user activities eligible for Handoff if the document is iCloud-based and the app’s `Info.plist` property list file includes a `CFBundleDocumentTypes` key of `NSUbiquitousDocumentUserActivityType`. The value of `NSUbiquitousDocumentUserActivityType` is a string that represents the <doc://com.apple.documentation/documentation/Foundation/NSUserActivity> object’s activity type. The document’s URL is in the <doc://com.apple.documentation/documentation/Foundation/NSUserActivity> object’s <doc://com.apple.documentation/documentation/Foundation/NSUserActivity/userInfo> dictionary with the [`NSUserActivityDocumentURLKey`](/documentation/AppKit/NSUserActivityDocumentURLKey).

In macOS, <doc://com.apple.documentation/documentation/Foundation/NSUserActivity> objects that [`NSDocument`](/documentation/AppKit/NSDocument) manage automatically become current when any of the document window controller’s windows become main. Otherwise, you need to invoke <doc://com.apple.documentation/documentation/Foundation/NSUserActivity/becomeCurrent()> at appropriate times.

AppKit automatically invalidates any <doc://com.apple.documentation/documentation/Foundation/NSUserActivity> objects that have no associated documents or responders.

You can use this property from any thread. It’s KVO-observable in case you share the [`NSDocument`](/documentation/AppKit/NSDocument) object with other objects that need to be in sync as the document moves into and out of iCloud.

## See Also

[`NSDocument`](/documentation/AppKit/NSDocument)

An abstract class that defines the interface for macOS documents.



---

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)