userActivity
An object encapsulating a user activity supported by this responder.
Declaration
var userActivity: NSUserActivity? { get set }Discussion
By setting the userActivity property on a responder, the NSUserActivity object becomes managed by AppKit. You should override updateUserActivityState(_:) to write lazily any state data representing the user’s activity to the userInfo dictionary. AppKit automatically saves user activities it manages at appropriate times. Multiple responders can share a single NSUserActivity instance, in which case they all get a callback, such as updateUserActivityState(_:), when the system updates the user activity object.
In macOS, NSUserActivity objects managed by NSResponder automatically becomeCurrent() based on the main window and the responder chain.
A responder object can set its userActivity property to nil if it no longer wants to participate. Any NSUserActivity objects that AppKit manages but have no associated responders (or documents) are automatically invalidated.
You can use this property from any thread, and it’s key-value observable (KVO).