The NSArray returned by tableColumns changes to removeTableColumn . Do not assume that he has not changed.
Although it returns as a non-mutable NSArray, the underlying implementation is changing, and it is unsafe to use NSEnumerator with modified collections. In the while loop, you send the nextObject message to the enumerator whose current object was just deleted — bad things can happen!
Here's a more efficient implementation:
NSTableColumn* col; while ((col = [[tableView tableColumns] lastObject])) { [tableView removeTableColumn:col]; }
When there are no columns in the table view: tableColumns returns an empty array, lastObject in an empty array returns nil, col sets nil, the condition false, and the while loop ends.
source share