是否可以通过编程方式确定类具有哪些属性?

发布于 2025-01-02 09:53:44 字数 296 浏览 3 评论 0原文

是否可以通过编程方式确定类具有哪些属性?我想查看类(或子类)定义了哪些属性。有人告诉我这与运行时内省有关。我找到了这篇文章,但它似乎只是冰山一角。

那么,是否可以通过编程方式确定一个类具有哪些属性?如何?

编辑:

我使用的是 iOS,而不是 Mac OS X。我需要导入哪些标头?

Is it possible to determine what properties a class has programmatically? I want to see what properties a class (or subclass) has defined. I'm told this has to do with something called runtime introspection. I've found this article, but it seems to be just the tip of the iceberg.

So, is it possible to determine what properties a class has programmatically? How?

Edit:

I'm working on iOS, not Mac OS X. What headers do I need to import?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2025-01-09 09:53:44

Objective-C 运行时编程指南包括一个部分关于列出属性。实际获取列表的相关片段是:

id LenderClass = objc_getClass("Lender");
unsigned int outCount;
objc_property_t *properties = class_copyPropertyList(LenderClass, &outCount);

然后,您使用运行时属性函数来获取有关列表中每个属性的任何信息。

The Objective-C Runtime Programming Guide includes a section about listing properties. The relevant snippet that actually gets the list is:

id LenderClass = objc_getClass("Lender");
unsigned int outCount;
objc_property_t *properties = class_copyPropertyList(LenderClass, &outCount);

Then you use the runtime property functions to get whatever information you want about each property in the list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文