iOS:跟踪NSSet对象的顺序

时间:2014-04-02 02:53:53

标签: ios model nsmutablearray nsset xcdatamodel

我想要一个可变的NSSet照片,并将照片随机存储在我的Xcode xcdatamodel中。我知道NSSet用于存储随机对象,但有没有办法将NSSet更改为NSArray或跟踪NSSet变量中的序列插入?

Article.h

@property (nonatomic, retain) NSSet *photos;

Article.m

RKManagedObjectMapping *_mapping = (RKManagedObjectMapping*)[RKManagedObjectMapping generatedManagedObjectMappingFromClass:[self class] keyUnderscored:NO excludesProperties:[NSArray arrayWithObjects:@"attachments", @"videos", @"photos", nil]];
[_mapping mapKeyPath:@"photos.photo" toRelationship:@"photos" withMapping:(RKManagedObjectMapping*)[BTAttachment rkObjectMapping]];
[_mapping mapKeyPath:@"attachments.attachment" toRelationship:@"attachments" withMapping:(RKManagedObjectMapping*)[BTAttachment rkObjectMapping]];

[更新]

我意识到即使我用过

[_model.photos allObjects] objectAtIndex:0]

每次刷新时0索引仍在变化。

1 个答案:

答案 0 :(得分:0)

NSOrderedSet维持订单。

您还可以使用setWithArray:allObjects在NSSet和NSArray之间来回转换