【发布时间】:2014-04-10 21:39:53
【问题描述】:
我有 2 个实体:chat> chatMessages(每个聊天有 0+ 条消息,每条消息属于一个聊天)。
我正在发送FetchedResultsController,我想按最后一条消息的日期对聊天进行排序:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ChatModel" inManagedObjectContext:[NSManagedObjectContext MR_defaultContext]];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"chatMessages.messageDate" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
但是通过这段代码我得到:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
如何按要求的方式对聊天进行排序? (就像whatsapp一样)
【问题讨论】:
标签: ios nsfetchedresultscontroller nssortdescriptor