簡體   English   中英

NSInvocation-如何從forwardInvocation內部找出消息的發送者:

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

sourceObject和destinationObject都是SameClass的實例。 SameClass是一個Singleton。 本質上,同一對象具有兩個不同的名稱,並且在方法級別具有基於此的行為。 我有以下幾行代碼:(這里有一個對稱性,我需要它們調用相同的方法,但是要在兩種不同情況下的兩個不同位置)

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


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

singleton1Object或singleton2Object都不實現增加:相反,它們都使用它來沿各自的方向(其他對象)定向消息。

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

有什么方法可以確定代碼的哪一部分最初接收到singleton1Object或singleton2Object的增加:並根據我在forwardInvocation內部進行路由的決定:

注意:Singleton向自己發送消息,他既是發送者又是接收者。 他用代碼中的兩個或多個名稱引用自己,並將其存儲在其中的兩個變量中,他一直這樣做,直到從一個方法到另一個他不了解的方法為止,在這種情況下,他將消息轉發到另一個對象。 我在代碼中的位置(主要由singleton1Object和singleton2Object或其他技術確定)可以提供將消息轉發到何處的線索。 編輯了問題,請參閱編輯以獲取更多詳細信息。

forwardInvocationself是消息的接收者。

調用對象不包含有關消息的初始發送者的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM