0

I am having 8 methods in my application, and each one is calling a single method -(void)someFunction,

How to know from inside the -(void)someFunction which one of those 8 methods called it ?

All suggestions are appreciated.

Thanks

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
Biranchi
  • 16,120
  • 23
  • 124
  • 161

4 Answers4

3

Re-think your design. Your methods should neither know nor care about the code that invokes them. Anything they need to know should be in the parameters they receive.

NSResponder
  • 16,861
  • 7
  • 32
  • 46
2

One way is to add an int parameter to someFunction and the calling method can identify itself with a unique value.

For example:

-(void)someFunction:(int)callerId { //switch or if stmt here based on callerId }

Then calling method A would call someFunction with callerId 1, method B with callerId 2, etc.

1

This seems easy--pass an argument to the function that determines which method it was.

0

I'm not very familiar with Objective C, but it seems like you want a stack trace. You might be able to get this by throwing an exception. (Some languages have a way of getting at the stack trace in other ways, but like I said, I'm not familiar enough with Objective C to know.) Related question on StackOverflow.

Community
  • 1
  • 1
Benjamin Oakes
  • 12,262
  • 12
  • 65
  • 83