开发者

Core Date One-To-One Sorting

开发者 https://www.devze.com 2023-03-15 23:26 出处:网络
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

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:

  1. Bids with no Result sorted by date
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消