4

The documentation for Cocoa's NSFetchRequest fetchLimit property says:

The fetch limit specifies the maximum number of objects that a request should return when executed.

If you set a fetch limit, the framework makes a best effort to improve efficiency, but does not guarantee it.

However, it doesn't tell you how to unlimit the maximum number of objects that a request should return if the fetch limit has already been set.

How can I return an unlimited number of matching objects after the previously limiting the number of objects with fetchLimit on my NSFetchRequest?

Josh Sherick
  • 2,161
  • 3
  • 20
  • 37

1 Answers1

12

From some quick testing, the default value for fetchLimit when an NSFetchRequest is instantiated is 0, and setting the value to something other than 0 and then back to 0 will not limit the results returned.

So, as of Swift 4, set fetchLimit to 0 to return unlimited results.

Josh Sherick
  • 2,161
  • 3
  • 20
  • 37
  • Sadly missing in the documentation, but I suppose it makes little sense wanting to limit a fetch request to zero items. – bompf Jan 11 '19 at 10:09