Search code examples
indexingnsarraynsmutablearray

NSArrayM objectAtIndex: index 5 beyond bounds for empty array


I'm trying to use the code from here: https://github.com/leah/PullToRefresh

but when I too big of a "pull height", I get a crash and this message:

NSArrayM objectAtIndex: index 5 beyond bounds for empty array

If my tableview cell only visit 4 cells, the crash message is instead

NSArrayM objectAtIndex: index 4 beyond bounds for empty array

etc. Please advise.


Solution

  • Of course it is beyond bounds: your array is empty, you can not extract any object form it.

    If the array has n objects, you can retrieve up to index n - 1. An empty array has 0 objects, so you can not even retrieve index 0.