2014-04-02 37 views
0

我想要一个可变的NSSet照片,并将照片随机存储在我的Xcode xcdatamodel中。我知道NSSet用于存储随机对象,但有没有办法将NSSet更改为NSArray或跟踪NSSet变量中的序列插入?iOS:跟踪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索引仍在改变。

回答

0

NSOrderedSet维持这个顺序。

您还可以使用setWithArray:allObjects的NSSet和NSArray的

+0

之间来回变换的0指数仍然改变我每次刷新的时间。 –

+0

即使使用NSOrderedSet? – michaels

+0

谢谢!发现我需要将关系的属性从NSSet更改为NSOrderedSet。 –