Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为核心数据中的可转换属性编写SortDescriptor?_Iphone_Ipad_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

Iphone 为核心数据中的可转换属性编写SortDescriptor?

Iphone 为核心数据中的可转换属性编写SortDescriptor?,iphone,ipad,core-data,nsfetchedresultscontroller,Iphone,Ipad,Core Data,Nsfetchedresultscontroller,我有一个实体头,它有一个属性NSDictionary,它在模型中声明为可转换。现在我不想对fetchedRequestController中的头数组进行排序。传递nil或null对象会产生错误。请帮我处理一下急事 让我从上一次重新构造:如果我有一个实体,带有一个可转换的属性头。我在生成的类中将id类型更改为NSDictionary。我现在需要访问字典的键作为entity.attribute name.key。。。我得到了一个错误,因为这个类不是键的键值编码。。。围绕这个问题的工作是什么。 /

我有一个实体头,它有一个属性NSDictionary,它在模型中声明为可转换。现在我不想对fetchedRequestController中的头数组进行排序。传递nil或null对象会产生错误。请帮我处理一下急事

让我从上一次重新构造:如果我有一个实体,带有一个可转换的属性头。我在生成的类中将id类型更改为NSDictionary。我现在需要访问字典的键作为entity.attribute name.key。。。我得到了一个错误,因为这个类不是键的键值编码。。。围绕这个问题的工作是什么。

// Create and configure a fetch request with the Book entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"headers" inManagedObjectContext:self.tableCellGenericMoc];
[fetchRequest setEntity:entity];

// Create the sort descriptors array.
NSSortDescriptor *headersDescriptor = [[NSSortDescriptor alloc] initWithKey:@"headersDictionary" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:headersDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

// Create and initialize the fetch results controller.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.tableCellGenericMoc sectionNameKeyPath:@"headresDictionary" cacheName:@"Root"];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;

上面的选择器给出了一个错误,因为它无法对headersDictionary进行排序

为什么要在核心数据中存储NSDictionary?简单地说,就是做错了。如果您想要类似于字典的东西,只需在一对多关系的另一端创建一个子对象,该关系具有名称和值

如果您正确地设计了模型,那么您就不会遇到现在遇到的问题,您可以在NSFetchRequest中直接使用谓词进行筛选和排序描述符

更新
哦,谢谢你。。。问题是我从网上得到的词典没有固定的密钥结构。。所以我必须得到字典,因为它是一个可转换的属性

仍然没有任何意义。我描述的设计与在可转换对象中使用字典完全相同,只是它在核心数据级别很有用。在我描述的设计中,您不需要固定键


重新考虑一下您的设计,这个问题就变得无关紧要了。

当我试图更改排序描述符中的键路径时,fetchedResultsController是否也存储了SortDescriptor,但它仍然使用旧值?如何拥有可转换的NSDictionary属性或属性KVC,以便Enty.ArributenName。(字典中的键)是KVC或视为路径;哦,谢谢你。。。问题是我从网上得到的词典没有固定的密钥结构。。所以我必须得到字典,因为它是一个可转换的属性