如何通过类别扩展将属性添加到NSMutableArray? [英] How to add properties to NSMutableArray via category extension?

查看:94
本文介绍了如何通过类别扩展将属性添加到NSMutableArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用类别扩展"(即@interface NSMutableArray (MyExtension))子类化" NSMutableArray,以向该类添加新功能.但是,有没有一种方法可以使用类别扩展将新的 properties 添加到扩展中?

I know that I can "subclass" an NSMutableArray using "category extensions," i.e. @interface NSMutableArray (MyExtension), to add new functions to the class. However, is there a way using category extensions to also add new properties to the extension?

推荐答案

请注意,@interface NSMutableArray (MyStuff)类别,而不是类扩展.在这种情况下,它们是相似的,但实际上有很多不同的细节.

Note that @interface NSMutableArray (MyStuff) is a category and not a class extension. They are similar in this context, but actually do have quite a few different details.

您不能通过任何一种机制将存储添加到现有类.您可以使用关联参考来但是,将数据与实例相关联.

You can't add storage to an existing class through either mechanism. You can use Associative References to associate data with an instance, though.

这篇关于如何通过类别扩展将属性添加到NSMutableArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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