iPhone:NSSet保持排序顺序 [英] iPhone: NSSet keep sort order

查看:113
本文介绍了iPhone:NSSet保持排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSMutableArray有大约18个对象。他们是按照我想要的特定顺序。我必须将这些对象添加到NSSet中保存在Core Data中。

I have an NSMutableArray which has about 18 objects. They are in a specific order that I want. I have to add these objects into an NSSet to be saved in Core Data.

但是,一旦我使用[myObject.items allObjects]将它们从NSSet中拉出,它不会保持我添加对象的原始顺序。

But, once I pull them out of the NSSet using [myObject.items allObjects] it does not keep the original order that I added the objects as. How can I keep the order that I want, I don't want to have to resort them.

推荐答案

如果你不想要的话, t要排序它们你可以添加一个属性(例如 int indexInList )到代表在列表中的位置的对象。

If you don't want to sort them you can add a property (e.g. int indexInList) to the objects which stands for the position in the list.

但是,对于对象的属性排序列表也很容易。

But sorting the list in respect to a property of the objects would be very easy too with

- (void)sortUsingSelector:(SEL)comparator
- (void)sortUsingDescriptors:(NSArray *)sortDescriptors 
...

这篇关于iPhone:NSSet保持排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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