您可以向您的实体添加另一个sectionnum
类型为“Integer 16”的属性:
sectionnum, item, value
-----------------------
2, email-home, abc@xyz.com
2, email-work, xyz@abc.com
1, phone-home, 1234567890
1, phone-work, 0987654321
3, address-home, London
3, address-work, Edinburgh
然后在(第一个)排序描述符中使用sectionnum
as 键,并在节名键路径中使用:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"YourEntity"];
NSSortDescriptor *s1 = [NSSortDescriptor sortDescriptorWithKey:@"sectionnum" ascending:YES];
request.sortDescriptors = @[s1];
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:self.context
sectionNameKeyPath:@"sectionnum"
cacheName:nil];