A little bit of knowledge about variable arrays and small knowledge about variable Arrays
Recently, an error occurred while using the variable array of iOS. The error message is:
Reason: '-[_ NSCFArray removeObjectAtIndex:]: mutating method sent to immutable Object'
The literal meaning is that the variable array method is sent to an immutable object.
The declaration and initialization Code are as follows:
// Declare NSMutableArray * dataArray; // initialize dataArray = [NSMutableArray array];
By analyzing dataArray, we found that dataArray is assigned a value only after the data is requested from the server. The problem is that it should appear here.
[manager POST:requestUrl parameters:jsonDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"json: %@", responseObject); dataArray = responseObject; [self.tableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"%@", error); }];
Therefore, the problem should be that the returned value of responseObject is an immutable array. After the value is assigned, dataArray also becomes an immutable array.
If you want to continue using it, do some processing, for example:
dataArray = [NSMutableArray arrayWithArray:dataArray];
Reference: http://stackoverflow.com/questions/22381384/ios-error-nscfarray-removeobjectatindex-mutating-method-sent-to-immutable