0

目前我的应用程序中有以下数据模型: Record 是一个带有时间戳、类型、名称的抽象实体。我有 3 种类型的实体,它们是 Record 的子类。我的 NSFetchedResultsControllers 提取 Record 对象,并在我的表视图中按类对它们进行排序:

Event1 has record as abstract parent, there will be 10000 such events
Event2 has record as abstract parent, there will be 100 such events
Event3 has record as abstract parent, there will be 100 such events

事件 1 由系统生成,事件 2 和 3 由用户创建。

该系统的目的是在需要所有数据时更容易显示数据。

但是,我遇到了一个问题,我只想显示部分数据- 用户创建的事件并允许用户编辑它们。

如果我当前的数据模型是一种仅过滤和显示用户事件的有效方法(核心数据必须仅将少数事件与系统生成的事件分开),我会徘徊。我应该让系统生成的事件成为一个单独的实体吗?我是否应该担心这样的事情,或者核心数据是否已经足够优化,所以这样的事情并不重要?

下面是让我问这个问题的 NSFetchedResultsController:

          NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
            NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];

            [fetchRequest setSortDescriptors:sortDescriptors];

    //system-generated events do not have type defined, while user events do have a type
            NSPredicate* predicate  = [NSPredicate predicateWithFormat:@"SELF.type > %0"];
            [fetchRequest setPredicate:predicate];
//^What are the performnance implications of the above predicate?



            // Edit the section name key path and cache name if appropriate.
            // nil for section name key path means "no sections".
            NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
4

1 回答 1

0

亚历克斯,

如果您想要的只是用户事件,那么只需对该实体使用获取请求,而不是超类。

安德鲁

于 2012-10-19T12:00:03.793 回答