开发者

Determine the class of a singleton method's caller

开发者 https://www.devze.com 2023-02-19 15:33 出处:网络
I\'ve got a singleton object (in Objective C, for what that\'s worth). Given any particular method defined in the singleton, can I determine the class of the object which is calling it? Short of modif

I've got a singleton object (in Objective C, for what that's worth). Given any particular method defined in the singleton, can I determine the class of the object which is calling it? Short of modifying the method signature to require I pass an instance of the caller (because then I'd开发者_如何学Go have to modify code everywhere the method is called).

that is, given the call from myObj

[[MySingleton instance] myMethod];

can myMethod know that it's a myObj which is calling it? I want to avoid (if I can) having to change code to something like

[[MySingleton instance] myMethodCalledBy:self];
0

精彩评论

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