views:

66

answers:

4

hi all,

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

+2  A: 

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.

DyingCactus
A: 

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.

Benjamin Oakes
+1  A: 

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

Preston
+2  A: 

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