views:

46

answers:

2

I'd like to know if I should expect setFetchOffset to work in an NSFetchedResultsController.

Given a UITableView that displays rows like this from an NSFRC:
1
2
3
4
5

I expected that adding this line:

[fetchRequest setFetchOffset:1];

e.g. line 207 here: http://github.com/mandersen/FetchOffsetCase/blob/master/Classes/RootViewController.m

Would result in UITableView rows like:
2
3
4
5

But it doesn't change the values displayed in the table.

A: 

WHen you say you expect 2, 3, 4, 5 what do you mean? If you are expecting the index to be offset then that is incorrect. What it will do is grab the 2nd through 6th results returned by the NSFetchRequest.

Marcus S. Zarra
Thanks for replying Marcus. Given five entities in a MoC displayed in a UITableView via NSFRC, I expect that setting a fetchOffset:1 would skip the entity that was sorted first, then display the last four entities. I was surprised to find that setting a fetch offset had no effect, i.e. there were still five entities displayed in the UITableView.
Matt Andersen
The Github project linked above shows a simple case of the problem. Build and run to see a UITableView with rows labeled 1,2,3,4,5. Try changing the setFetchOffset value ~line 207 of the RootViewController and note that it has no effect on the rows displayed.My question is whether I'm doing it wrong or if I should expect offset to work at all with NSFRC.
Matt Andersen
In playing with this it does appear to be a bug. I can force it by playing with the `-fetchLimit` to act even more strangely. I would **highly** recommend that you file a radar on this and report back here with the radar number so that I (and anyone else watching this) can duplicate the radar.
Marcus S. Zarra
Bug ID# 8300567
Matt Andersen
A: 

setFetchOffset only works on persisted entities.

I figured this out while experiencing similar frustrations with NSFetchRequest setReturnsDistinctResults and found Michael Waterfall's question on that subject:

http://stackoverflow.com/questions/1632029/nsdictionaryresulttype-expression-not-taking-into-account-newly-inserted-objects

Matt Andersen