| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When an object is unable to respond to a message, the Objective-C
runtime sends a forwardInvocation: message to the object, and
the object is then able to use the information provided to handle the
message in some way, a common mechanism being to forward the message
to another object known as a delegate, so that the other object
can deal with it.
- (void) forwardInvocation: (NSInvocation*)objectInvoke
{
if ([forwardObject respondsToSelector: [objectInvoke selector]])
return [objectInvoke invokeWithTarget: forwardObject];
else
return [self doesNotRecognizeSelector: [objectInvoke selector]];
}
|
objectInvoke is another object (of the NSInvocation class)
which has all the information about the original message sent, including
its selector and its arguments.
self refers to the object or receiver.
Note. this is a powerful method for creating software patterns for multiple inheritance, journaling, and dispatching messages to dynamically loaded code.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Chat class passes the negotiate message to an instance of the ChatTwo class. The forwarding object therefore inherits methods from its own inheritance path and from that of the receiving object.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
forwardInvocation: method of the surrogate object receives a message that is to be forwarded; it determines whether or not the receiver exists, and if it does not, then it will attempt to create it. A proxy object is a common example of a surrogate object. A proxy object performs obvious functions that we have already discussed:
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
respondsToSelector and isKindOfClass:. This is because these methods search the inheritance path, but ignore the forwarding path.
(See Section 1.6.6 respondsToSelector.)
Note. respondsToSelector does not trace the forwarding chain, and can therefore erroneously report that an object does not respond to a particular message, when it does.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
General discussion about threading with gnustep base, what is thread-safe, what is not, how to start new threads, NSThread briefly introduced with examples.
[Nicola: important: talk about NSConnection enableMultipleThreads]].
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |