NSInvocationOperation Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
NSOperation.h
Related sample code

Overview

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.

Tasks

Initialization

Getting Attributes

Instance Methods

initWithInvocation:

Returns an NSInvocationOperation object initialized with the specified invocation object.

- (id)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.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSOperation.h

initWithTarget:selector:object:

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

- (id)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.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSOperation.h

invocation

Returns the receiver’s invocation object.

- (NSInvocation *)invocation
Return Value

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

Availability
  • Available in iOS 2.0 and later.
Declared In
NSOperation.h

result

Returns the result of the invocation or method.

- (id)result
Return Value

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

Discussion

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

Availability
  • Available in iOS 2.0 and later.
Declared In
NSOperation.h

Constants

Result Exceptions

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

extern NSString * const NSInvocationOperationVoidResultException;
extern NSString * const NSInvocationOperationCancelledException;
Constants
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.

Declared in NSOperation.h.

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.

Declared in NSOperation.h.

Declared In
NSOperation.h