2012-07-21 82 views
1

iCloud不支持關係的唯一集合的有序集合。現在,我創建了一個名爲'entryIndex'的屬性,它存儲它自己的索引值。當用戶刪除特定索引處的對象時,我想識別該對象並更改索引較高的對象的值。我該怎麼做呢?iCloud不支持有序集..替代解決方案?

+0

使用一個NSArray? – kennytm 2012-07-21 21:42:55

回答

1

假設你有連續的索引,並希望讓他們「從緊」無間隙:

NSArray *filtered = [fetchedObjects filteredArrayUsingPredicate: 
    [NSPredicate predicateWithFormat:@"entryIndex > %@", 
            deletedObject.entryIndex]]; 
for (NSManagedObject *obj in filtered) { 
    obj.entryIndex = [NSNumber numberWithInt:[obj.entryIndex intValue]-1]; 
} 
[self.managedObjectContext save:nil]; 
相關問題