开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜