简体   繁体   English

NSInvocation-如何从forwardInvocation内部找出消息的发送者:

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

Both sourceObject and destinationObject are instances of the SameClass. sourceObject和destinationObject都是SameClass的实例。 SameClass is a Singleton. SameClass是一个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) singleton1Object或singleton2Object都不实现增加:相反,它们都使用它来沿各自的方向(其他对象)定向消息。

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:? 有什么方法可以确定代码的哪一部分最初接收到singleton1Object或singleton2Object的增加:并根据我在forwardInvocation内部进行路由的决定:

NOTE: The Singleton send messages to itself he is both the sender and the receiver. 注意:Singleton向自己发送消息,他既是发送者又是接收者。 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. 我在代码中的位置(主要由singleton1Object和singleton2Object或其他技术确定)可以提供将消息转发到何处的线索。 Edited the question see edit for more details. 编辑了问题,请参阅编辑以获取更多详细信息。

In forwardInvocation , self is the receiver of the message. forwardInvocationself是消息的接收者。

The invocation object does not contain information about the initial sender of the message. 调用对象不包含有关消息的初始发送者的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM