Instance Property


An object that encapsulates a user activity supported by this document.


@property(strong) NSUserActivity *userActivity;


NSDocument automatically creates NSUserActivity objects for iCloud-based documents if the app’s Info.plist property list file includes a CFBundleDocumentTypes key of NSUbiquitousDocumentUserActivityType. The value of NSUbiquitousDocumentUserActivityType is a string that is used for the NSUserActivity object’s activity type. The document's URL is put into the NSUserActivity object’s userInfo dictionary with the NSUserActivityDocumentURLKey.

In macOS, NSUserActivity objects managed by NSDocument automatically becomeCurrent when any of the document window controller's window's become main. Otherwise, you need to invoke [[document userActivity] becomeCurrent] at appropriate times.

If the document becomes non-ubiquitous, its NSDocument property is nil. Any NSUserActivity objects that are managed by AppKit but which have no associated documents (or responders) are automatically invalidated.

This property can be used from any thread. It is KVO observable in case the NSDocument object is being shared with other objects that need to be kept in sync as the document moves into and out of iCloud.

See Also

Supporting User Activities

- updateUserActivityState:

Updates the state of the given user activity.


The key that identifies the document associated with a user activity.