我正在开发一款iOS闪存卡式学习应用程序,在加载时需要从Core Data中获取大量数据.但是我需要的数据是实体的一个相当特定的子集,基于用户设置,所以有多个谓词涉及测试等价.我发现这些提取速度非常慢,根据对SQLite的研究,我认为索引在这里是一个不错的选择.
现在,我理解(主要是通过阅读其他stackoverflow问题)SQLite和Core Data是两个不同的,基本上是正交的东西,不应该混淆.但是我的理解是你应该通过Core Data来完成任何类型的数据库工作和调整; 在优化或设计应用程序中的对象持久性时,不应试图绕过并直接使用SQLite.
但我唯一可以在Core Data中找到索引的是模型中每个属性的一个"索引"复选框.而这只是没有做我正在寻找的那种优化.
这是获取请求,目前:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"SKUserItem" inManagedObjectContext:context];
fetchRequest.entity = entity;
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"next" ascending:YES] autorelease];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSMutableArray *predicates = [NSMutableArray arrayWithCapacity:6];
[predicates addObject:[NSPredicate predicateWithFormat:@"next < %f", now() + (60.0*60.0*24.0)]];
[predicates addObject:[NSPredicate predicateWithFormat:@"next > %f", nextOffset]];
[predicates addObject:[NSPredicate predicateWithFormat:@"user == %@", user]];
[predicates addObject:[NSPredicate predicateWithFormat:@"langRaw == %d", lang]];
NSArray *stylePredicates = [NSArray arrayWithObjects:[NSPredicate predicateWithFormat:@"styleRaw == %d", SK_SIMP_AND_TRAD], [NSPredicate predicateWithFormat:@"styleRaw == %d", …Run Code Online (Sandbox Code Playgroud)