1

How do I get the sender of the message wrapped in an `NSInvocation?

I'm in an object, and I've just received an invocation in my forwardInvocation:. Is there any way to know who sent me the message in the first place?

jscs
  • 63,694
  • 13
  • 151
  • 195
unom
  • 11,438
  • 4
  • 34
  • 54
  • 1
    You may not be able to get the 'sender' as an object, but it is theoretically possible to get the calling function, as that should be somewhere on the stack, or in the link register. Probably not useful in 95% of applications, though. – Richard J. Ross III Apr 01 '14 at 02:28
  • Hmm... what would that function look like, is it something general or can I extract some information about the sender from it. – unom Apr 01 '14 at 19:55
  • You could use NSThread's `callStackSymbols` as a starting point. – Richard J. Ross III Apr 01 '14 at 21:16

1 Answers1

1

No. Information about the sender is not available (unless you explicitly add an sender:self argument).

See also this thread http://www.cocoabuilder.com/archive/cocoa/194746-is-the-sender-of-an-obj-method-implied-in-the-destination-method.html:

It isn't explicitly available, nor can you consistently unwind the stack to figure it out. Nor is there even a guarantee that the "sender" is really some Objective-C object; it could just as easily be a function or FFI produced closure, in the case of the various language bridges.

b.bum

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382