Objective C可以在运行时(反射)确定调用者对象引用吗? [英] Can Objective C determine the caller object reference at runtime (reflection)?

查看:56
本文介绍了Objective C可以在运行时(反射)确定调用者对象引用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Objective C是一种比C#或Java更具动态性的语言。在C#中,您只能知道调用者对象的类(使用stacktrace),而不知道调用者本身的实例引用。



Objective C对此更有能力吗? / p>

更新:我在这里查看了另一篇文章如何确定来电者?我在Objective-C中的方法?。据我所知,它只给出了类名。我坚持认为我不仅仅通过课程名称感兴趣,而是通过获得调用者实例本身的参考。

解决方案

这已在这里得到解答:



如何确定调用者?我在Objective-C中的方法是什么?



但答案并不是特别漂亮。除了搜索堆栈之外,看起来没有简单,可靠的方法来执行此操作,这可能是操作系统版本或平台依赖。



为什么你想要做什么这个?也许你的问题还有另一个解决方案。


As far as I understand Objective C is a much more dynamic language than C# or Java. In C# you can only know the class of the caller object (using stacktrace) but not the instance reference of the caller itself.

Is Objective C more capable for this ?

Update: I looked the other post here How can I determine the "caller" of my method in Objective-C?. As far as I understand it only gives Class Name. I insist that I'm not interested only by class name but by getting a ref to the caller instance itself.

解决方案

This has already been answered here:

How can I determine the "caller" of my method in Objective-C?

The answer's not particularly pretty though. It looks like there's no simple, reliable way to do it other than hunting through the stack, which might be OS version or platform dependent.

Why exactly did you want to do this? Perhaps there's another solution to your problem.

这篇关于Objective C可以在运行时(反射)确定调用者对象引用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆