0

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

文章.h

@property (nonatomic, retain) NSSet *photos;

文章.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 索引仍在变化。

4

1 回答 1

0

NSOrderedSet维护顺序。

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

于 2014-04-02T02:57:24.143 回答