在Objective-c中获取对象名称 [英] Getting object name in Objective-c

查看:165
本文介绍了在Objective-c中获取对象名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Foo类和一个myFoo类的实例:

suppose i have a class Foo and an instance of this class myFoo:

Foo *myFoo;

有没有可以显示对象名称的方法"dispalyFooObjectName",例如:

is there any method "dispalyFooObjectName" that can display the name of the object, for exmample :

NSLog(@"i was called from %s", [myFoo dispalyFooObjectName]);

结果将是:

i was called from myFoo

推荐答案

在大多数编程语言中,对象没有名称.仅仅因为某些变量myFoo引用了您的对象,并不意味着您的对象被称为" myFoo.

In most programming languages objects don't have names. Just because some variable myFoo references your object, doesn't mean that your object is "called" myFoo.

在大多数基于C的语言中,变量名称根本没有在最终的可执行文件中表示(外部符号的名称除外).

And in most C-based languages variable names are not represented in the final executables at all (except for the names of external symbols).

因此,简短的答案是无法获取该信息.

So the short answer is that there's no way to get to that information.

如果需要一些名称",则应在Foo类型中添加一个name字段.

If you want some "name", then you should add a name field to your Foo type.

这篇关于在Objective-c中获取对象名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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