removeAllObjects crashes app
ios, ipad, iphone, nsarray, objective-c
Solution
'-[__NSArrayI removeAllObjects]: unrecognized selector sent to instance
This means that the array doens't have the method you're trying to call. That's because it is an immutable array (`NSArray`), not mutable (`NSMutableArray`).
Either make it mutable if you want to mutate it. Or, replace:
[msg_array removeAllObjects];
with:
msg_array = @[];
Based on your comment, the array should be mutable. That means that you have a mutable property / instance variable, but that you're creating an immutable instance to store into it. Find that location and update it (to create / return a `mutableCopy` at least).
Problem
I want to clear my array, what i did is, I have tableview view in my app, first i am fetching data from server and loading it in tableView. ``` -(void)viewDidLoad{ //fetching data from server using background thread and storing it in array called (msg_array) [table reloadData]; } ``` when last row comes on screen i want to fetch new data from server and i want to display it, ``` -(void)LoadMoreData{ //this method gets fire when last cell is on screen if ([msg_array count]>0) { [msg_array removeAllObjects]; //crashes here } } ``` This gives the error: ``` Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeAllObjects]: unrecognized selector sent to instance ``` Why does it cause a crash: The array is allocated like this: ``` msg_array = [dictShow copy]; ``` dictshow contains the data and copying it to msg_array and dictshow is mutabledictionary (Taken from comments)