开发者

Objective C - Is it possible to obtain the name or pointer to the object calling a method?

开发者 https://www.devze.com 2023-02-17 06:20 出处:网络
I have set up an Objective C logging class, however I would like to know the object that sent the message to the log class.

I have set up an Objective C logging class, however I would like to know the object that sent the message to the log class.

All of the logging examples seem to wrap the objective C classes around C macros, which entails that the logging will be in C function syntax; I would like to stick with an Objective C syntax.

Can anyone assist in how开发者_开发问答 to retrieve the source of a message?

Thanks in advance,


Nope; can't be done. At least, not consistently and, even then, not without a massive performance hit.

This seems to be coming up often lately.

Finding where a method was called from


I usually pass information from the caller to NSLog by:

 NSLog(@"%@::%@", [[self class] description], NSStringFromSelector(_cmd));

Not sure whether it is what you want though.

0

精彩评论

暂无评论...
验证码 换一张
取 消