当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Check Method Caller Source? Objective-C

问题描述:

I have a method which calls itself. I.E

-(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.

Any help much appreciated, thanks.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: