iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIResponder Class Reference

Options
Deployment Target:

On This Page
Language:

UIResponder

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

The UIResponder class defines an interface for objects that respond to and handle events. It is the superclass of UIApplication, UIView and its subclasses (which include UIWindow). Instances of these classes are sometimes referred to as responder objects or, simply, responders.

There are two general kinds of events: touch events and motion events. The primary event-handling methods for touches are touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:, and touchesCancelled:withEvent:. The parameters of these methods associate touches with their events—€”especially touches that are new or have changed—€”and thus allow responder objects to track and handle the touches as the delivered events progress through the phases of a multi-touch sequence. Any time a finger touches the screen, is dragged on the screen, or lifts from the screen, a UIEvent object is generated. The event object contains UITouch objects for all fingers on the screen or just lifted from it.

iOS 3.0 introduced system capabilities for generating motion events, specifically the motion of shaking the device. The event-handling methods for these kinds of events are motionBegan:withEvent:, motionEnded:withEvent:, and motionCancelled:withEvent:. Additionally for iOS 3.0, the canPerformAction:withSender: method allows responders to validate commands in the user interface while the undoManager property returns the nearest NSUndoManager object in the responder chain.

In iOS 4.0, UIResponder added the remoteControlReceivedWithEvent: method for handling remote-control events.

  • Returns the receiver'€™s next responder, or nil if it has none.

    Declaration

    Swift

    func nextResponder() -> UIResponder?

    Objective-C

    - (UIResponder *)nextResponder

    Return Value

    The next object in the responder chain to be presented with an event for handling.

    Discussion

    The UIResponder class does not store or set the next responder automatically, instead returning nil by default. Subclasses must override this method to set the next responder. UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value indicating whether the receiver is the first responder.

    Declaration

    Swift

    func isFirstResponder() -> Bool

    Objective-C

    - (BOOL)isFirstResponder

    Return Value

    YEStrue if the receiver is the first responder, NOfalse otherwise.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value indicating whether the receiver can become first responder.

    Declaration

    Swift

    func canBecomeFirstResponder() -> Bool

    Objective-C

    - (BOOL)canBecomeFirstResponder

    Return Value

    YEStrue if the receiver can become the first responder, NOfalse otherwise.

    Discussion

    Returns NOfalse by default. If a responder object returns YEStrue from this method, it becomes the first responder and can receive touch events and action messages. Subclasses must override this method to be able to become first responder.

    You must not send this message to a view that is not currently attached to the view hierarchy. The result is undefined.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Notifies the receiver that it is about to become first responder in its window.

    Declaration

    Swift

    func becomeFirstResponder() -> Bool

    Objective-C

    - (BOOL)becomeFirstResponder

    Return Value

    YEStrue if the receiver accepts first-responder status or NOfalse if it refuses this status. The default implementation returns YEStrue, accepting first responder status.

    Discussion

    Subclasses can override this method to update state or perform some action such as highlighting the selection.

    A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.

    You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns a Boolean value indicating whether the receiver is willing to relinquish first-responder status.

    Declaration

    Swift

    func canResignFirstResponder() -> Bool

    Objective-C

    - (BOOL)canResignFirstResponder

    Return Value

    YEStrue if the receiver can resign first-responder status, NOfalse otherwise.

    Discussion

    Returns YEStrue by default. As an example, a text field in the middle of editing might want to implement this method to return NOfalse to keep itself active during editing.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Notifies the receiver that it has been asked to relinquish its status as first responder in its window.

    Declaration

    Swift

    func resignFirstResponder() -> Bool

    Objective-C

    - (BOOL)resignFirstResponder

    Discussion

    The default implementation returns YEStrue, resigning first responder status. Subclasses can override this method to update state or perform some action such as unhighlighting the selection, or to return NOfalse, refusing to relinquish first responder status. If you override this method, you must call super (the superclass implementation) at some point in your code.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • inputView inputView Property

    The custom input view to display when the receiver becomes the first responder. (read-only)

    Declaration

    Swift

    var inputView: UIView? { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIView *inputView

    Discussion

    This property is typically used to provide a view to replace the system-supplied keyboard that is presented for UITextField and UITextView objects.

    The value of this read-only property is nil. A responder object that requires a custom view to gather input from the user should redeclare this property as read-write and use it to manage its custom input view. When the receiver becomes the first responder, the responder infrastructure presents the specified input view automatically. Similarly, when the receiver resigns its first responder status, the responder infrastructure automatically dismisses the specified input view.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The custom input view controller to use when the receiver becomes the first responder. (read-only)

    Declaration

    Swift

    var inputViewController: UIInputViewController? { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIInputViewController *inputViewController

    Discussion

    This property is typically used to provide a view controller to replace the system-supplied keyboard that is presented for UITextField and UITextView objects.

    The value of this read-only property is nil. If you want to provide a custom input view controller to replace the system keyboard in your app, redeclare this property as read-write in a UIResponder subclass.. You can then use this property to manage a custom input view controller. When the receiver becomes the first responder, the responder infrastructure presents the specified input view controller automatically. Similarly, when the receiver resigns its first responder status, the responder infrastructure automatically dismisses the specified input view controller.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

    See Also

    inputView

  • The custom input accessory view to display when the receiver becomes the first responder. (read-only)

    Declaration

    Swift

    var inputAccessoryView: UIView? { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIView *inputAccessoryView

    Discussion

    This property is typically used to attach an accessory view to the system-supplied keyboard that is presented for UITextField and UITextView objects.

    The value of this read-only property is nil. If you want to attach custom controls to a system-supplied input view (such as the system keyboard) or to a custom input view (one you provide in the inputView property), redeclare this property as read-write in a UIResponder subclass. You can then use this property to manage a custom accessory view. When the receiver becomes the first responder, the responder infrastructure attaches the accessory view to the appropriate input view before displaying it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The custom input accessory view controller to display when the receiver becomes the first responder. (read-only)

    Declaration

    Swift

    var inputAccessoryViewController: UIInputViewController? { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIInputViewController *inputAccessoryViewController

    Discussion

    This property is typically used to attach an accessory view controller to the system-supplied keyboard that is presented for UITextField and UITextView objects.

    The value of this read-only property is nil. If you want to attach custom controls to a system-supplied input view controller (such as the system keyboard) or to a custom input view (one you provide in the inputViewController property), redeclare this property as read-write in a UIResponder subclass. You can then use this property to manage a custom accessory view. When the receiver becomes the first responder, the responder infrastructure attaches the accessory view to the appropriate input view before displaying it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Updates the custom input and accessory views when the object is the first responder.

    Declaration

    Swift

    func reloadInputViews()

    Objective-C

    - (void)reloadInputViews

    Discussion

    You can use this method to refresh the custom input view or input accessory view associated with the current object when it is the first responder. The views are replaced immediately—that is, without animating them into place. If the current object is not the first responder, this method has no effect.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Tells the receiver when one or more fingers touch down in a view or window.

    Declaration

    Swift

    func touchesBegan(_ touches: Set<NSObject>, withEvent event: UIEvent)

    Objective-C

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    Parameters

    touches

    A set of UITouch instances that represent the touches for the starting phase of the event represented by event.

    event

    An object representing the event to which the touches belong.

    Discussion

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example,

    Swift

    • super.touchesBegan(touches, withEvent: event)

    Objective-C

    • [super touchesBegan:touches withEvent:event];

    If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.

    Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YEStrue.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the receiver when one or more fingers associated with an event move within a view or window.

    Declaration

    Swift

    func touchesMoved(_ touches: Set<NSObject>, withEvent event: UIEvent)

    Objective-C

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

    Parameters

    touches

    A set of UITouch instances that represent the touches that are moving during the event represented by event.

    event

    An object representing the event to which the touches belong.

    Discussion

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example,

    Swift

    • super.touchesMoved(touches, withEvent: event)

    Objective-C

    • [super touchesMoved:touches withEvent:event];

    Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YEStrue.

    If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the receiver when one or more fingers are raised from a view or window.

    Declaration

    Swift

    func touchesEnded(_ touches: Set<NSObject>, withEvent event: UIEvent)

    Objective-C

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

    Parameters

    touches

    A set of UITouch instances that represent the touches for the ending phase of the event represented by event.

    event

    An object representing the event to which the touches belong.

    Discussion

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example,

    Swift

    • super.touchesEnded(touches, withEvent: event)

    Objective-C

    • [super touchesEnded:touches withEvent:event];

    When an object receives a touchesEnded:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.

    Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YEStrue.

    If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event.

    Declaration

    Swift

    func touchesCancelled(_ touches: Set<NSObject>!, withEvent event: UIEvent!)

    Objective-C

    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

    Parameters

    touches

    A set of UITouch instances that represent the touches for the ending phase of the event represented by event.

    event

    An object representing the event to which the touches belong.

    Discussion

    This method is invoked when the Cocoa Touch framework receives a system interruption requiring cancellation of the touch event; for this, it generates a UITouch object with a phase of UITouchPhaseCancel. The interruption is something that might cause the application to be no longer active or the view to be removed from the window

    When an object receives a touchesCancelled:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example,

    Swift

    • super.touchesCancelled(touches, withEvent: event)

    Objective-C

    • [super touchesCancelled:touches withEvent:event];

    If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Tells the receiver that a motion event has begun.

    Declaration

    Swift

    func motionBegan(_ motion: UIEventSubtype, withEvent event: UIEvent)

    Objective-C

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

    Parameters

    motion

    An event-subtype constant indicating the kind of motion. A common motion is shaking, which is indicated by UIEventSubtypeMotionShake.

    event

    An object representing the event associated with the motion.

    Discussion

    iOS informs the first responder only when a motion event starts and when it ends; for example, it doesn’t report individual shakes. The receiving object must be the first responder to receive motion events.

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the receiver that a motion event has ended.

    Declaration

    Swift

    func motionEnded(_ motion: UIEventSubtype, withEvent event: UIEvent)

    Objective-C

    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

    Parameters

    motion

    An event-subtype constant indicating the kind of motion. A common motion is shaking, which is indicated by UIEventSubtypeMotionShake.

    event

    An object representing the event associated with the motion.

    Discussion

    iOS informs the responder only when a motion event starts and when it ends; for example, it doesn’t report individual shakes.

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the receiver that a motion event has been cancelled.

    Declaration

    Swift

    func motionCancelled(_ motion: UIEventSubtype, withEvent event: UIEvent)

    Objective-C

    - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event

    Parameters

    motion

    An event-subtype constant indicating the kind of motion associated with event. A common motion is shaking, which is indicated by UIEventSubtypeMotionShake.

    event

    An object representing the event associated with the motion.

    Discussion

    This method is invoked when the Cocoa Touch framework receives an interruption requiring cancellation of the motion event. This interruption is something that might cause the application to be no longer active or the view to be removed from the window. The method can also be invoked if the shaking goes on too long. All responders that handle motion events should implement this method; in it they should clean up any state information that was established in the motionBegan:withEvent: implementation.

    The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Sent to the receiver when a remote-control event is received.

    Declaration

    Swift

    func remoteControlReceivedWithEvent(_ event: UIEvent)

    Objective-C

    - (void)remoteControlReceivedWithEvent:(UIEvent *)event

    Parameters

    event

    An event object encapsulating a remote-control command. Remote-control events have a type of UIEventTypeRemoteControl.

    Discussion

    Remote-control events originate as commands from external accessories, including headsets. An application responds to these commands by controlling audio or video media presented to the user. The receiving responder object should examine the subtype of event to determine the intended command—for example, play (UIEventSubtypeRemoteControlPlay)—and then proceed accordingly.

    To allow delivery of remote-control events, you must call the beginReceivingRemoteControlEvents method of UIApplication; to turn off delivery of remote-control events, call endReceivingRemoteControlEvents.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.0 and later.

  • Returns the nearest shared undo manager in the responder chain. (read-only)

    Declaration

    Swift

    var undoManager: NSUndoManager? { get }

    Objective-C

    @property(nonatomic, readonly) NSUndoManager *undoManager

    Discussion

    By default, every window of an application has an undo manager: a shared object for managing undo and redo operations. However, the class of any object in the responder chain can have their own custom undo manager. (For example, instances of UITextField have their own undo manager that is cleared when the text field resigns first-responder status.) When you request an undo manager, the request goes up the responder chain and the UIWindow object returns a usable instance.

    You may add undo managers to your view controllers to perform undo and redo operations local to the managed view.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Requests the receiving responder to enable or disable the specified command in the user interface.

    Declaration

    Swift

    func canPerformAction(_ action: Selector, withSender sender: AnyObject?) -> Bool

    Objective-C

    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender

    Parameters

    action

    A selector that identifies a method associated with a command. For the editing menu, this is one of the editing methods declared by the UIResponderStandardEditActions informal protocol (for example, copy:).

    sender

    The object calling this method. For the editing menu commands, this is the shared UIApplication object. Depending on the context, you can query the sender for information to help you determine whether a command should be enabled.

    Return Value

    YEStrue if the the command identified by action should be enabled or NOfalse if it should be disabled. Returning YEStrue means that your class can handle the command in the current context.

    Discussion

    This default implementation of this method returns YEStrue if the responder class implements the requested action and calls the next responder if it does not. Subclasses may override this method to enable menu commands based on the current state; for example, you would enable the Copy command if there is a selection or disable the Paste command if the pasteboard did not contain data with the correct pasteboard representation type. If no responder in the responder chain returns YEStrue, the menu command is disabled. Note that if your class returns NOfalse for a command, another responder further up the responder chain may still return YEStrue, enabling the command.

    This method might be called more than once for the same action but with a different sender each time. You should be prepared for any kind of sender including nil.

    For information on the editing menu, see the description of the UIMenuController class.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • Returns the target object that responds to an action.

    Declaration

    Swift

    func targetForAction(_ action: Selector, withSender sender: AnyObject?) -> AnyObject?

    Objective-C

    - (id)targetForAction:(SEL)action withSender:(id)sender

    Parameters

    action

    A selector that identifies a method associated with a command.

    sender

    The object calling this method. For the editing menu commands, this is the shared UIApplication object. Depending on the context, you can query the sender for information to help you determine the target of the command.

    Return Value

    The object whose action method is invoked to execute the command.

    Discussion

    This method is called whenever an action needs to be invoked by the object. The default implementation calls the canPerformAction:withSender: method to determine whether it can invoke the action. If the object can invoke the action, it returns itself, otherwise it passes the request up the responder chain. Your app should override this method if it wants to override how a target is selected.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The key commands that trigger actions on this responder. (read-only)

    Declaration

    Swift

    var keyCommands: [AnyObject]? { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *keyCommands

    Discussion

    A responder object that supports hardware keyboard commands can redefine this property and use it to return an array of UIKeyCommand objects that it supports. Each key command object represents the keyboard sequence to recognize and the action method of the responder to call in response.

    The key commands you return from this method are applied to the entire responder chain. When an key combination is pressed that matches a key command object, UIKit walks the responder chain looking for an object that implements the corresponding action method. It calls that method on the first object it finds and then stops processing the event.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • The text input mode for this responder object. (read-only)

    Declaration

    Swift

    var textInputMode: UITextInputMode? { get }

    Objective-C

    @property(nonatomic, readonly, retain) UITextInputMode *textInputMode

    Discussion

    The text input mode identifies the language and keyboard displayed when this responder is active.

    For responders, the system normally displays a keyboard that is based on the user’s language preferences. You can redefine this property and use it to return a different text input mode in cases where you want a responder to use a specific keyboard. The user can still change the keyboard while the responder is active, but switching away to another responder and then back restores the keyboard you specified.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • An identifier signifying that the responder should preserve its text input mode information. (read-only)

    Declaration

    Swift

    var textInputContextIdentifier: String? { get }

    Objective-C

    @property(nonatomic, readonly, retain) NSString *textInputContextIdentifier

    Discussion

    If you redefine this property and return a string value, UIKit tracks the current text input mode for the responder. While in tracking mode, any programmatic changes you make to the text input mode are remembered and restored whenever the responder becomes active.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Clears text input mode information from the app’s user defaults.

    Declaration

    Swift

    class func clearTextInputContextIdentifier(_ identifier: String)

    Objective-C

    + (void)clearTextInputContextIdentifier:(NSString *)identifier

    Parameters

    identifier

    An identifier assigned to the textInputContextIdentifier property of one of your responders.

    Discussion

    Calling this method removes any text input mode information associated with the specified identifier from the app’s user defaults. Removing this information causes the responder to use the default text input mode again.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • An object encapsulating a user activity supported by this responder.

    Declaration

    Swift

    var userActivity: NSUserActivity?

    Objective-C

    @property(nonatomic, retain) NSUserActivity *userActivity

    Discussion

    By setting the userActivity property on a responder, the NSUserActivity object becomes managed by UIKit. User activities managed by UIKit are saved automatically at appropriate times. You can lazily add state data representing the user’s activity via the updateUserActivityState: override. Multiple responders can share a single NSUserActivity instance, in which case they all get an updateUserActivityState: callback.

    A responder object can set its userActivity property to nil if it no longer wants to participate. Any NSUserActivity objects that are managed by UIKit but which have no associated responders (or documents) are automatically invalidated.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Restores the state needed to continue the given user activity.

    Declaration

    Swift

    func restoreUserActivityState(_ activity: NSUserActivity)

    Objective-C

    - (void)restoreUserActivityState:(NSUserActivity *)activity

    Parameters

    activity

    The user activity to be continued.

    Discussion

    Subclasses override this method to restore the responder’s state with the given user activity. The system calls it on any objects passed to the restoration handler given to application:continueUserActivity:restorationHandler:. The override should use the state data contained in the given user activity’s userInfo dictionary to restore the object.

    You may also call this method directly if the app delegate chooses not to use the restoration handler.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Updates the state of the given user activity.

    Declaration

    Swift

    func updateUserActivityState(_ activity: NSUserActivity)

    Objective-C

    - (void)updateUserActivityState:(NSUserActivity *)activity

    Parameters

    activity

    The user activity to be updated.

    Discussion

    Subclasses override this method to update the state of the given user activity. You should add state representing the user's activity into the NSUserActivity object using its addUserInfoEntriesFromDictionary: method. When the state is dirty, you should set the needsSave property of the NSUserActivity to YEStrue, and this method will be called at an appropriate time.

    When an NSUserActivity object managed by UIKit is updated, an empty userInfo dictionary is given to the NSUserActivity object, and all of the objects associated with the NSUserActivity are then sent an updateUserActivityState: message.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.