I have a core data model that has two entities, Bid and Result.
I want them sorted initially in a section where the bid has no result i.e. the relationship from Bid to Result is nil, then I want this sub sorted by date.
Ideally I would have two sections:
- Bids with no Result sorted by date
- Bids with a result sorted by date
Due to the relationship being potentially nil I see very erratic results. Using two NSSortDescriptors first sorting on the relationship and then on the date will work for a few entries then seems to randomly blow up.
E.g.
NSSortDescriptor *sectionSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"result" ascending:YES];
NSSortDescriptor *dateSortDescriptor =开发者_C百科 [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
How should I sort entities by a relationship that could potentially be nil?
A nil should evaluate to zero and non-nil to non-zero so you can sort on nils. I think the problem maybe elsewhere.
I would suggest trying to sort just with the nils and see if that works. That at least will tell you where the problem is.
精彩评论