Core data 具有fetchOffset的NSFetchRequest不';我们不能返回预期的结果

Core data 具有fetchOffset的NSFetchRequest不';我们不能返回预期的结果,core-data,nsfetchrequest,Core Data,Nsfetchrequest,我在尝试从核心数据获取“分页”实体时遇到了一些奇怪的情况 以下是我用于获取的代码: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.ma

我在尝试从核心数据获取“分页”实体时遇到了一些奇怪的情况

以下是我用于获取的代码:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" 
                                          inManagedObjectContext:self.managedObjectContext];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"userIdentifier beginswith[cd] %@ AND selected == 1",userIdentifier];
fetchRequest.fetchOffset = offset;
fetchRequest.fetchLimit = limit;
[fetchRequest setEntity:entity];
NSLog(@"offset %d limit %d",fetchRequest.fetchOffset,fetchRequest.fetchLimit);

NSError *requestError = nil;
NSArray *items = [self.managedObjectContext executeFetchRequest:fetchRequest
                                                          error:&requestError];
NSLog(@"fetched items count = %d",items.count);
以下是日志:

2013-01-31 16:01:28.127 offset 0 limit 100
2013-01-31 16:01:28.128 fetched items count = 6
2013-01-31 16:01:40.533 offset 1 limit 100
2013-01-31 16:01:40.535 fetched items count = 5
2013-01-31 16:01:53.029 offset 2 limit 100
2013-01-31 16:01:53.032 fetched items count = 4
2013-01-31 16:01:55.468 offset 3 limit 100
2013-01-31 16:01:55.470 fetched items count = 3
2013-01-31 16:02:00.776 offset 4 limit 100
2013-01-31 16:02:00.779 fetched items count = 2
2013-01-31 16:02:02.325 offset 5 limit 100
2013-01-31 16:02:02.328 fetched items count = 1
2013-01-31 16:02:03.837 offset 6 limit 100
2013-01-31 16:02:03.839 fetched items count = 0
2013-01-31 16:02:07.714 offset 6 limit 100
2013-01-31 16:02:07.717 fetched items count = 0
对于这个测试,我有6个“用户”条目

我做错了什么


谢谢,您的日志表明一切正常


恭喜你

您的日志表明一切正常

恭喜你

找到了问题:

fetchRequest.fetchOffset = offset*limit;
发现问题:

fetchRequest.fetchOffset = offset*limit;

是的,我发现了问题。是的,我发现了问题。