Inherits from NSObject
Declared in A2BlockInvocation.h

Overview

An A2BlockInvocation is an Objective-C block call rendered static, that is, it is an action turned into an object. A2BlockInvocation objects are used to store and forward closure invocations between objects, primarily by the A2DynamicDelegate system.

A block invocation object can be repeatedly dispatched with multiple sets of arguments with the same flexibility as NSInvocation. This design makes A2BlockInvocation extremely useful, because blocks can be used to capture scope and a block invocation can be used to save it for later.

Like NSInvocation, A2BlockInvocation does not support invocations of methods with variadic arguments or union arguments.

Tasks

Other Methods

Creating A2BlockInvocation Objects

Getting the Block and Method Signatures

  •   methodSignature

    The receiver’s method signature, reflecting the block with a selector. Appropriate for use in -methodSignatureForSelector:.

    property
  •   block

    Returns the receiver’s block.

    property
  • – invokeWithInvocation:returnValue:

    Calls the receiver’s block with the arguments from the given invocation, providing a buffer containing the block’s return value upon return.

  • – invokeWithInvocation:

    Calls the receiver’s block with the arguments from the given invocation and sets the return value on the given invocation.

Properties

block

@property (nonatomic, copy, readonly) id block
Discussion

Returns the receiver’s block.

Declared In

A2BlockInvocation.h

methodSignature

@property (nonatomic, strong, readonly) NSMethodSignature *methodSignature
Discussion

The receiver’s method signature, reflecting the block with a selector. Appropriate for use in -methodSignatureForSelector:.

Declared In

A2BlockInvocation.h

Class Methods

methodSignatureForBlock:

+ (NSMethodSignature *)methodSignatureForBlock:(id)block
Discussion

Inspects the given block literal and returns a compatible method signature.

The returned method signature is suitable for use in the Foundation forwarding system to link a method call to a block invocation.

Parameters

block

An Objective-C block literal

Return Value

A method signature matching the declared prototype for the block

Declared In

A2BlockInvocation.h

Instance Methods

initWithBlock:

- (instancetype)initWithBlock:(id)block
Discussion

Returns a block invocation object able to construct calls to a given block.

This method synthesizes a compatible method signature for the given block.

Parameters

block

A block literal

Return Value

An initialized block invocation object

Declared In

A2BlockInvocation.h

initWithBlock:methodSignature:

- (instancetype)initWithBlock:(id)block methodSignature:(NSMethodSignature *)methodSignature
Discussion

Returns a block invocation object able to construct calls to a given block using a given Objective-C method signature.

The method signature given must be compatible with the signature of the block; that is, equal to the block signature but with a SEL (':') as the second parameter. Passing in an incompatible method signature will raise an exception.

An example method returning a string for an integer argument would have the following properties: - Block type signature of NSString *(^)(int) - Block function definition of NSString *(*)(id, int) - Block signature of "@@?i" - Method signature of "@:i" or "@i"

Parameters

block

An Objective-C block literal

methodSignature

An method signature matching the block

Return Value

An initialized block invocation object

Declared In

A2BlockInvocation.h

invokeWithInvocation:

- (void)invokeWithInvocation:(NSInvocation *)inv
Discussion

Calls the receiver’s block with the arguments from the given invocation and sets the return value on the given invocation.

Parameters

inv

An instance of NSInvocation with values for its arguments set.

Declared In

A2BlockInvocation.h

invokeWithInvocation:returnValue:

- (BOOL)invokeWithInvocation:(NSInvocation *)inv returnValue:(out NSValue **)returnValue
Discussion

Calls the receiver’s block with the arguments from the given invocation, providing a buffer containing the block’s return value upon return.

Parameters

inv

An instance of NSInvocation with values for its arguments set.

returnValue

On return, the block’s return value, or nil for a void return type.

NO

if the buffer copies necessary for invocation failed, YES otherwise.

Declared In

A2BlockInvocation.h