I'm using a UITableView to show some data from an array. This array can be changed at any time by other threads. (I believe that whether the array is mutable, or just replaced entirely, doesn't make a difference.) Access to the array itself is threadsafe.
What's the proper way to ensure thread safety with regard to the tableview? I'm worried, for example, that I might change the array to be shorter just before cellForRowAtIndexPath is called, leading to an NSRangeException.
Should I...
- Enforce that the array is only changed on the main thread? (Seems ugly.)
- Maintain a shadow array and update this on the main thread through KVO observing?
- ??? There must be a better solution...