Up

NSInvocation class reference

Authors

Richard Frith-Macdonald (richard@brainstorm.co.uk)
Andrew Kachites McCallum (mccallum@gnu.ai.mit.edu)

Version: 1.60

Date: 2003/08/24 23:07:40

Copyright: (C) 1998,2003 Free Software Foundation, Inc.


Contents -

  1. Software documentation for the NSInvocation class
  2. Software documentation for the NSInvocation(GNUstep) category
  3. Software documentation for the NSInvocation(MacroSetup) category

Software documentation for the NSInvocation class

NSInvocation : NSObject

Declared in:
Foundation/NSInvocation.h
Standards:

The NSInvocation class implements a mechanism of constructing messages (as NSInvocation instances), sending these to other objects, and handling the returned values.

An NSInvocation object may contain a target object to which a message can be sent, or may send the message to an arbitrary object.
Each message consists of a selector for that method and an argument list. Once the message has been sent, the invocation will contain a return value whose contents may be copied out of it.

The target, selector, and arguments of an instance be constructed dynamically, providing a great deal of power/flexibility.

The sending of the message to the target object (using the -invoke or -invokeWithTarget: method) can be done at any time, but a standard use of this is by the [NSObject -forwardInvocation:] method which is called whenever a method is not implemented by the class of the object to which it was sent.

Related to the class are two convenience macros... NS_MESSAGE() and NS_INVOCATION() to allow easy construction of invocations with all the arguments set up.



Instance Variables for NSInvocation Class

_argsRetained

@private BOOL _argsRetained;

Description forthcoming.


_cframe

@private void* _cframe;

Description forthcoming.


_dummy

@private void* _dummy;

Description forthcoming.


_info

@private NSArgumentInfo* _info;

Description forthcoming.


_numArgs

@private unsigned int _numArgs;

Description forthcoming.


_retval

@private void* _retval;

Description forthcoming.


_selector

@private SEL _selector;

Description forthcoming.


_sendToSuper

@private BOOL _sendToSuper;

Description forthcoming.


_sig

@private NSMethodSignature* _sig;

Description forthcoming.


_target

@private id _target;

Description forthcoming.


_validReturn

@private BOOL _validReturn;

Description forthcoming.





Method summary

invocationWithMethodSignature: 

+ (NSInvocation*) invocationWithMethodSignature: (NSMethodSignature*)_signature;

Returns an invocation instance which can be used to send messages to a target object using the described signature.
You must set the target and selector (using -setTarget: and -setSelector:) before you attempt to use the invocation.
Raises an NSInvalidArgumentException if the signature is nil.


argumentsRetained 

- (BOOL) argumentsRetained;

Returns a flag to indicate whether object arguments of the invocation (including its target) are retained by the invocation.


getArgument: atIndex: 

- (void) getArgument: (void*)buffer atIndex: (int)index;

Copies the argument identified by index into the memory location specified by the buffer argument.
An index of zero is the target object, an index of one is the selector, so the actual method arguments start at index 2.


getReturnValue: 

- (void) getReturnValue: (void*)buffer;

Copies the invocations return value to the location pointed to by buffer if a return value has been set (see the -setReturnValue: method).
If there isn't a return value then this method raises an exception.


invoke 

- (void) invoke;

Sends the message encapsulated in the invocation to its target.


invokeWithTarget: 

- (void) invokeWithTarget: (id)anObject;

Sends the message encapsulated in the invocation to anObject.


methodSignature 

- (NSMethodSignature*) methodSignature;

Returns the method signature of the invocation.


retainArguments 

- (void) retainArguments;

Instructs the invocation to retain its object arguments (including the target). The default is not to retain them.


selector 

- (SEL) selector;

Returns the selector of the invocation (the argument at index 1)


setArgument: atIndex: 

- (void) setArgument: (void*)buffer atIndex: (int)index;

Sets the argument identified by index from the memory location specified by the buffer argument.
Using an index of 0 is equivalent to calling -setTarget: and using an argument of 1 is equivalent to -setSelector:
Proper arguments start at index 2.
NB. Unlike -setTarget: and -setSelector: the value of buffer must be a pointer to the argument to be set in the invocation.
If -retainArguments was called, then any object argument set in the receiver is retained by it.


setReturnValue: 

- (void) setReturnValue: (void*)buffer;

Sets the return value of the invocation to the item that buffer points to.


setSelector: 

- (void) setSelector: (SEL)aSelector;

Sets the selector for the invocation.


setTarget: 

- (void) setTarget: (id)anObject;

Sets the target object for the invocation.
If -retainArguments was called, then the target is retained.


target 

- (id) target;

Returns the target object of the invocation.


Software documentation for the NSInvocation(GNUstep) category

NSInvocation(GNUstep)

Declared in:
Foundation/NSInvocation.h
Standards:

Provides some minor extensions and some utility methods to aid integration of NSInvocation with the ObjectiveC runtime.

Method summary

initWithArgframe: selector: 

- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector;

Internal use.
Initialises the receiver with a known selector and argument list as supplied to the forward:: method by the ObjectiveC runtime when it is unable to locate an implementation for mthe selector in a class.


initWithMethodSignature: 

- (id) initWithMethodSignature: (NSMethodSignature*)aSignature;
This is a designated initialiser for the class.
Subclasses should override this method.

Initialised an invocation instance which can be used to send messages to a target object using aSignature.
You must set the target and selector (using -setTarget: and -setSelector:) before you attempt to use the invocation.
Raises an NSInvalidArgumentException if aSignature is nil.


initWithSelector: 

- (id) initWithSelector: (SEL)aSelector;

Tries to produce a method signature based on aSelector and uses that to initialise self by calling the -initWithMethodSignature: method.
If the argument type of aSelector cannot be determined, this releases self and returns nil.


initWithTarget: selector: ,...

- (id) initWithTarget: (id)anObject selector: (SEL)aSelector,...;

Initialises the reciever with the specified target, selector, and a variable number of arguments.


returnFrame: 

- (void*) returnFrame: (arglist_t)argFrame;

Internal use.
Provides a return frame that the ObjectiveC runtime can use to return the result of an invocation to a calling function.


sendsToSuper 

- (BOOL) sendsToSuper;

Returns the status of the flag set by -setSendsToSuper:


setSendsToSuper: 

- (void) setSendsToSuper: (BOOL)flag;

Sets the flag to tell the invocation that it should actually invoke a method in the superclass of the target rather than the method of the target itsself.
This extension permits an invocation to act like a regular method call sent to super in the method of a class.


Software documentation for the NSInvocation(MacroSetup) category

NSInvocation(MacroSetup)

Declared in:
Foundation/NSInvocation.h
Standards:

These methods are for internal use only... not public API
They are used by the NS_INVOCATION() and NS_MESSAGE() macros to help create invocations.

Method summary

_newProxyForInvocation: 

+ (id) _newProxyForInvocation: (id)target;

Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.


_newProxyForMessage: 

+ (id) _newProxyForMessage: (id)target;

Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.


_returnInvocationAndDestroyProxy: 

+ (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy;

Warning the underscore at the start of the name of this method indicates that it is private, for internal use only, and you should not use the method in your code.



Up