1

I am a newbie so the question might sound silly. But how could I know the sender of a method in Objective-C? In some situations like Target/Action, sender is obvious (a UIControl object). But what about viewDidLoad?

While receiver of an method is usually obvious, sender is not so. For example, I have to read the documentation to know that dealloc's sender is runtime and runtime only. Is there a way to know the sender of a method more easily?

Philip007
  • 3,190
  • 7
  • 46
  • 71
  • Set some breakpoints and you can see the stack trace and who's calling your methods. If you're lost at that idea, google settings breakpoints in Xcode – Jessedc Aug 07 '12 at 13:06
  • What are you attempting to identify? viewDidLoad will fire when it does just that, i.e. when the view is loaded and displayed. Normally viewDidload would not be the method or delegated method of an objects event, so I am unclear what you trying to derive in viewDidLoad. – ross_t Aug 07 '12 at 13:07
  • possible duplicate of [How to find out who called a method?](http://stackoverflow.com/questions/1793999/how-to-find-out-who-called-a-method), [Get the object which called a method](http://stackoverflow.com/questions/6120258/get-the-object-which-called-a-method?lq=1) – jscs Aug 07 '12 at 16:19

1 Answers1

2

If you aren't passed information from caller then it's not important; this stands for all programming languages; a method is provided with the data/object to work on and it doesn't matter what called the method. This makes the method more useful.

You don't say why it's important to know who the sender is; if it's just curiosity then you can set a breakpoint and examine the stacktrace in the debugger.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I used to think that sender is as important as receiver is in message passing. That's why I got worried whenever I don't know who the sender is. Guess I have no need to worry. – Philip007 Aug 07 '12 at 13:34