Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray removeAllObjects results in a crash
    primarykey
    data
    text
    <p>I have an <code>NSMutableArray</code> in my <code>ViewController</code> which is the datasource for my <code>UITableView</code> defined like so:</p> <pre><code>NSMutableArray *messageArray; </code></pre> <p>I have a method to reload the tableView data, before which, I want to clear the existing table data.</p> <p>If I use the following code: </p> <pre><code> [messageArray removeAllObjects]; [self.tableView reloadData]; </code></pre> <p>I get the following exception: </p> <blockquote> <p>2013-02-12 14:20:30.378 appname[20998:907] <strong>* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object' *</strong> First throw call stack: (0x3939e3e7 0x35dd6963 0x3939e307 0x393200e7 0x392eb5e5 0x7cda3 0x3a236047 0x3a2360d1 0x3a236047 0x3a235ffb 0x3a235fd5 0x3a23588b 0x3a235d79 0x3a15e5c9 0x3a14b8b1 0x3a14b1bf 0x336305f7 0x33630227 0x393733e7 0x3937338b 0x3937220f 0x392e523d 0x392e50c9 0x3362f33b 0x3a19f291 0x79c11 0x39be4b20) libc++abi.dylib: terminate called throwing an exception</p> </blockquote> <p>But if I use the following code, it works.</p> <pre><code> NSMutableArray *emptyArray = [NSMutableArray new]; messageArray = emptyArray; [self.tableView reloadData]; </code></pre> <p>Why am I getting an error for <code>removeAllObjects</code>? Could this be the culprit?</p> <pre><code> NSMutableDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil]; messageArray = responseDictionary[@"data"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload