Core data 属性为dictionary的实体的谓词

Core data 属性为dictionary的实体的谓词,core-data,ios7,nsdictionary,nspredicate,Core Data,Ios7,Nsdictionary,Nspredicate,我有一个简单的coredata实体,看起来像这样 @interface Event : NSManagedObject @property (nonatomic, retain) NSNumber id; @property (nonatomic, retain) NSString * location; @property (nonatomic, retain) id eventType; // this is a dictioary @end eventType属性是一个如下所示的

我有一个简单的coredata实体,看起来像这样

@interface Event : NSManagedObject

@property (nonatomic, retain) NSNumber id;
@property (nonatomic, retain) NSString * location;
@property (nonatomic, retain) id eventType;  // this is a dictioary


@end
eventType属性是一个如下所示的字典

eventType":{"id":1,"typeDescription":"Sale"}
我一直在尝试获取所有eventType的typeDescription keyValue为Sale的事件对象

具有该值的实体肯定存在于我的数据库中,但我得到的结果为零

这是我执行提取的代码

- (NSFetchedResultsController *)fetchedResultsController
{
    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }




    NSManagedObjectContext *managedObjectContext = RKObjectManager.sharedManager.managedObjectStore.mainQueueManagedObjectContext;

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
     NSPredicate  *eventTypePredicate=[NSPredicate predicateWithFormat:@"eventType.typeDescription == %@",@"Sale"];

    NSCompoundPredicate *compoundPredicate ;
    compoundPredicate=[[NSCompoundPredicate alloc]initWithType:NSAndPredicateType subpredicates:@[eventTypePredicate]];
    [fetchRequest setPredicate:eventTypePredicate];
    [fetchRequest setFetchBatchSize:20];

      NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"id" ascending:YES];
    NSArray *sortDescriptors = @[sortDescriptor];
    [fetchRequest setSortDescriptors:sortDescriptors];

     NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&error]) {
        // Replace this implementation with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return _fetchedResultsController;
}

在核心数据中存储词典的唯一方法是将其归档为NSData

单击“属性类型”下拉列表时,您将看到支持的类型列表:

请注意,字典不是其中之一。这是因为字典是一种非常复杂的对象类型,其树长度在运行时未定义。由于核心数据是一个对象持久性框架,所以在尝试对对象运行查询之前,它需要了解所有对象的信息

因此,在核心数据中存储字典的最大限制是,您无法搜索嵌套在字典中的任何值,因为它们必须作为二进制数据持久化


既然您说您需要找到typeDescription值为Sale的所有实体,那么您已经部分回答了您自己的问题。只需使用字符串类型创建属性typeDescription。然后,您只需要搜索所有实体,其中typeDescription=Sale

将eventType定义为可转换属性?