NSInvocation - How to figure out who the message was directed to from inside forwardInvocation:

StackOverflow https://stackoverflow.com/questions/22744155

  •  24-06-2023
  •  | 
  •  

Question

Both sourceObject and destinationObject are instances of the SameClass. SameClass is a Singleton. Essentially the same object goes by two different names and has behavior at method level which is different based on that. I have these lines of code: (there is a symmetry here, I need them to call the same method but in two different places under two different circumstances)

//some code in some place
    [singleton1Object increase: 20];


//some code in a completely different place
    [singleton2Object increase: 40];

Neither singleton1Object or singleton2Object implement increase: instead they both use it to direct the message each in their respective directions (other objects)

forwardInvocation
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
    //determine where the message came from
}

Is there any way to determine which part of the code singleton1Object or singleton2Object initially received increase: and base my decision of where to route, on that, from inside forwardInvocation:?

NOTE: The Singleton send messages to itself he is both the sender and the receiver. He refers to itself by two or more names in code, stored in two of it's variable, he keeps doing this until it gets from method to method to one he does not understand in which case he forwards the message to another object. Where I am in the code, mainly determined by singleton1Object and singleton2Object or some other technique has the clue to where I should forward my messages. Edited the question see edit for more details.

Was it helpful?

Solution

In forwardInvocation, self is the receiver of the message.

The invocation object does not contain information about the initial sender of the message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top