iOS Developer Library

Developer

Foundation Framework Reference NSInvocationOperation Class Reference

Options
Deployment Target:

On This Page
Language:

NSInvocationOperation

Inherits From


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later

The NSInvocationOperation class is a concrete subclass of NSOperation that manages the execution of a single encapsulated task specified as an invocation. You can use this class to initiate an operation that consists of invoking a selector on a specified object. This class implements a non-concurrent operation.

For more information on concurrent versus non-concurrent operations, see NSOperation Class Reference.

  • Returns an NSInvocationOperation object initialized with the specified target and selector.

    Declaration

    Objective-C

    - (instancetype)initWithTarget:(id)target selector:(SEL)sel object:(id)arg

    Parameters

    target

    The object defining the specified selector.

    sel

    The selector to invoke when running the operation. The selector may take 0 or 1 parameters; if it accepts a parameter, the type of that parameter must be id. The return type of the method may be void, a scalar value, or an object that can be returned as an id type.

    arg

    The parameter object to pass to the selector. If the selector does not take an argument, specify nil.

    Return Value

    An initialized NSInvocationOperation object or nil if the target object does not implement the specified selector.

    Discussion

    If you specify a selector with a non-void return type, you can get the return value by calling the result method after the operation finishes executing. The receiver tells the invocation object to retain its arguments.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 2.0 and later

  • Returns an NSInvocationOperation object initialized with the specified invocation object.

    Declaration

    Objective-C

    - (instancetype)initWithInvocation:(NSInvocation *)inv

    Parameters

    inv

    The invocation object identifying the target object, selector, and parameter objects.

    Return Value

    An initialized NSInvocationOperation object or nil if the object could not be initialized.

    Discussion

    This method is the designated initializer. The receiver tells the invocation object to retain its arguments.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 2.0 and later

  • The receiver’s invocation object. (read-only)

    Declaration

    Objective-C

    @property(readonly, retain) NSInvocation *invocation

    Discussion

    The invocation object identifying the target object, selector, and parameters to use to execute the operation’s task.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 2.0 and later

  • result result Property

    The result of the invocation or method. (read-only)

    Declaration

    Objective-C

    @property(readonly, retain) id result

    Discussion

    The object returned by the method or an NSValue object containing the return value if it is not an object. nil if the method or invocation is not finished executing.

    If an exception was raised during the execution of the method or invocation, accessing this property raises that exception again. If the operation was cancelled or the invocation or method has a void return type, accessing this property raises an exception; see “Result Exceptions”.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 2.0 and later

  • Names of exceptions raised by NSInvocationOperation if there is an error when calling the result method.

    Declaration

    Swift

    let NSInvocationOperationVoidResultException: String let NSInvocationOperationCancelledException: String

    Objective-C

    extern NSString * const NSInvocationOperationVoidResultException; extern NSString * const NSInvocationOperationCancelledException;

    Constants

    • NSInvocationOperationVoidResultException

      NSInvocationOperationVoidResultException

      The name of the exception raised if the result method is called for an invocation method with a void return type.

      Available in iOS 2.0 and later

    • NSInvocationOperationCancelledException

      NSInvocationOperationCancelledException

      The name of the exception raised if the result method is called after the operation was cancelled.

      Available in iOS 2.0 and later