获取目标c中所有类的实例? [英] Get all instances of a class in objective c?
问题描述
我有一个有很多实例的UIView,每个实例都有一个UIRecognizer。
I have a UIView that has many instances and each one of them has a UIRecognizer.
当点击它们时,我想删除所有的识别器其他。
When on of them is tapped I want to remove all the recognizers of the others.
我希望它能获得课程的所有实例并删除他们的认可。
What I want it to get all the instances of the class and remove their recognizes.
I知道ManagedObjects有 [Entity allObjects];
I know ManagedObjects has [Entity allObjects];
如何创建all objects类方法?
How can I create my "all objects" class method ?
推荐答案
我有两个想法:
1 /创建一个类数组所有实例静态NSArray *实例;
,在初始化时注册它们,在解除分配时注销。该数组应该只有弱引用,否则永远不会被释放。
1/ Create a class array with all the instances static NSArray* instances;
, register them when initializing, unregister when deallocating. The array should have only weak references, otherwise they will never be deallocated.
2 / NSNotification。所有实例都可以等待通知,如果您点按,则会发送通知。
2/ NSNotification. All instances can wait for a notification and if you tap, you send the notification.
这篇关于获取目标c中所有类的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!