Fetching a large data set with Core-Data

I needed loop over a potentially large set of data stored in Core Data, but did not want to force the system to load the entire data set in memory or have Core Data constantly process faults. There seem to be several ways to do this, some easier than others. One robust way would be to use an NSFetchedResultController, but it looked a little more complex than I wanted to deal with ( and involves implementing yet another protocol).

After poking around the NSFetchResult class page for a while I noticed these methods: setFetchLimit and setFetchOffset. It turns out that these are just like the LIMIT and OFFSET keywords in SQL, which is just what I was looking for.

Using this method is just a few extra lines of code. This is what it looks like:

0 comments:

Post a Comment