Instance Property


An object encapsulating a user activity supported by this document.


var userActivity: NSUserActivity? { get set }


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.

On iOS, for NSUserActivity objects managed by UIKit to become current, you must either call becomeCurrent() explicitly or have the document’s NSUserActivity object also set on a UIViewController object that is in the view hierarchy when the app comes to the foreground.

If the document becomes non-ubiquitous, its userActivity 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 userActivity 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

func restoreUserActivityState(NSUserActivity)

Restores the state needed to continue the given user activity.

func updateUserActivityState(NSUserActivity)

Updates the state of the given user activity.