I have an NSOperationQueue
whose operations are constantly manipulating the instance variable myMutableArray
in the background (both adding and removing elements). maxConcurrentOperationCount
is set to 1
, so there should never be more than one operation manipulating the array at the same time.
myMutableArray
is used in an NSTableView
's data source methods as well. [tableView reloadData]
is being called on the main thread by each individual NSOperation
after it has finished manipulating myMutableArray
.
Now for my problem: Occasionally, I get the following exception:
-[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
from within tableView:objectValueForTableColumn:row:
.
I don't understand why exactly this can occur when I am running my operations one at a time. What can I do to prevent it from happening?