如何在我的SQLite表中获取项目7 000到7 999,大约有10万个项目?
正常的提取回归到很多工作,我宁可一点一点地获取它:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Log"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&err];
// here fetchedObjects holds around 100 000 rows
executeFetchRequest:fetchRequest
?答案 0 :(得分:2)
使用fetchLimit
上的fetchOffset
和NSFetchRequest
属性来获取所选范围内的对象。
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.fetchLimit = 1000;
fetchRequest.fetchOffset = 7000;
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Log"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&err];