0

Assuming that I have an array that contains 25 objects within. How can I do to filter the array with range from 20 to 30? I know that I can use - subarrayWithRange:. But if the range is out of the existed object range, then it will be crashed.

In SQLite we can use limit(location, length) to retrieve result. So I think is there a way that I can approach this?

Edit:

I may express the question a little fuzzy, is there any syntax in NSPredicate like "limit(location, length)" in SQLite? then I don't need to check the max anymore?

Seraph J. Lin
  • 123
  • 1
  • 2
  • 8
  • 1
    Before sending the message subarrayWithRange, check if the range is valid. NSPredicate is pretty optimized if the predicate is not complex 25 objects is not a limiti – Andrea Mar 25 '15 at 17:11
  • 1
    why dont you just query the length of the array and limit the upper bound to that retrieved length? – luk2302 Mar 25 '15 at 17:11

1 Answers1

0

Get count of your array, then set range max as array.count. If array.count is less than the range this should avoid crashes. Else if array.count is = with predefined range max this is another case. When array.count is over predefined range max there is no problem. Hope this helps.

ares777
  • 3,590
  • 1
  • 22
  • 23
  • That's exactly how I do now, but my question is, is there any syntax in NSPredicate like "limit(location, length)" in SQLite? then I don't need to check the max anymore? – Seraph J. Lin Mar 26 '15 at 02:18