1

I have a method which calls itself:

-(void)myMethod
{
     //do stuff
     [self myMethod];
     //do stuff
}

I need to check, from inside myMethod where it is being called from. For example, IF called myMethod do this, ELSE do this.

halfer
  • 19,824
  • 17
  • 99
  • 186
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
  • possible duplicate of [Objective C find caller of method](http://stackoverflow.com/questions/1451342/objective-c-find-caller-of-method) – Glorfindel Jun 23 '15 at 16:17
  • Can you pass a parameter to myMethod? That's the standard way of handling recursion. – i_am_jorf Jun 23 '15 at 16:30

1 Answers1

4

Can you just pass in a boolean to show called from external vs called from recursion?

-(void)myMethod:(bool)externalCall
{
     //do stuff
     [self myMethod:false];
     //do stuff
}

And then call that from outside with:

[self myMethod:true];

That may be over simplifying, especially if you need to get the calling method from multiple different locations (instead of recursion vs external call), but it seems to me the simplest answer to your presented problem.

Putz1103
  • 6,211
  • 1
  • 18
  • 25