Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot change mutable array?
    primarykey
    data
    text
    <p>Ok so I have been stuck on this for a while even though it's a simple problem, I am trying to add an NSDictionary to an array however when calling the addObject method on the array the program crashes claiming I am sending a mutating method to an immutable object. </p> <p>my code looks like:</p> <pre><code> - (IBAction)btnSaveMessage:(id)sender { //Save The Message and Clear Text Fields NSMutableDictionary *newMessageDictionary = [[NSMutableDictionary alloc] init]; [newMessageDictionary setObject:@"plist test title" forKey:@"Title"]; [newMessageDictionary setObject:@"plist subtitle" forKey:@"Subtitle"]; [newMessageDictionary setObject:@"-3.892119" forKey:@"Longitude"]; [newMessageDictionary setObject:@"54.191707" forKey:@"Lattitude"]; NSMutableArray *messagesArray =[[NSMutableArray alloc]init]; //Load Plist into array NSString *messagesPath = [[NSBundle mainBundle] pathForResource:@"Messages" ofType:@"plist"]; messagesArray = [NSArray arrayWithContentsOfFile:messagesPath]; [messagesArray addObject:newMessageDictionary]; //this causes crash //write messagesarray to file NSString *plistPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; plistPath = [plistPath stringByAppendingPathComponent:@"usersMessages.plist"]; [messagesArray writeToFile:plistPath atomically:YES]; </code></pre> <p>So I understand that I am trying to add to what the compiler see's as an immutable array but I declared it as Mutable?</p> <p>Whats going on? :(</p>
    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.
    1. This table or related slice is empty.
    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