Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:36:30+00:00 2026-05-31T00:36:30+00:00

I have an array of dictionaries from a JSON feed. This populates a UITableView

  • 0

I have an array of dictionaries from a JSON feed. This populates a UITableView. When the user selects a row I use the UITableViewCellAccessoryCheckmark, and I’m trying to modify the dictionary inside the array for that row, so when the cell is reused again after a scroll it stays correct. However I’m getting an error. Here’s my code (shortened for clarity):

JSON data method:

+ (NSMutableArray *)parseKennelData:(NSString *)type userID:(NSString *)user dogID:(NSString *)dog terms:(NSString *)terms
{
   NSURL *searchURL=[NSURL URLWithString:searchLocation];

   // download and parse the JSON
   NSData *JSONData = [[[NSData alloc] initWithContentsOfURL:searchURL] autorelease ];

   NSError *error=nil;
   CJSONDeserializer *deserializer = [CJSONDeserializer deserializer];
   NSMutableDictionary *JSONdictionary =[deserializer deserializeAsDictionary:JSONData error:&error]; 

   NSMutableArray *allResults = [JSONdictionary valueForKey:@"kennel"];

   return allResults;
}

View Controller:

interface
{
    NSMutableArray *results;
}

- (void)viewDidLoad
{
    //  data for search
    self.results=[JSONData parseKennelData:@"search" userID:@"demo" dogID:@"" terms:self.terms];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSMutableDictionary *rowData = [self.results objectAtIndex:[indexPath row]];

    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];

    if (thisCell.accessoryType == UITableViewCellAccessoryNone) 
    {        
        thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
        thisCell.accessoryView = [[UIImageView alloc]
                          initWithImage:[UIImage imageNamed:@"tick-button.png"]]; 
        [rowData setObject:@"demo" forKey:@"user_id" ];        
    }
    else
    {
        thisCell.accessoryType = UITableViewCellAccessoryNone;  
        thisCell.accessoryView = [[UIImageView alloc]
                              initWithImage:[UIImage imageNamed:@"plusbutton.png"]];
        [rowData setObject:@"" forKey:@"user_id"];
    }

    [self.results replaceObjectAtIndex:[indexPath row] withObject:rowData];
}

I’m getting a SIGABRT error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'

I thought I’d made sure all my stuff is mutable, so I can’t see where it’s falling over.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:36:31+00:00Added an answer on May 31, 2026 at 12:36 am

    You say you made sure all your stuff immutable, but just declaring your *JSONDictionary, *allResults, and *rowData pointers to be mutable doesn’t make them mutable. The mutability of those objects depends entirely on the right hand side of the assignment.

    From the error you’re getting, it’s clear that the dictionaries you’re trying to edit in didSelectRowAtIndexPath: are immutable. Also, I’m not familiar with TouchJSON but I’m pretty sure allResults is immutable too.

    To rectify this, you need to make two changes, in both cases using the convenient mutableCopy method to make a mutable copy of an immutable array or dictionary. First, make the array returned by parseKennelData:userID:dogID:terms: mutable:

    NSMutableArray *allResults = [[JSONdictionary valueForKey:@"kennel"] mutableCopy];
    

    And then, in tableView:didSelectRowAtIndexPath:, make a mutable copy of the dictionary before modifying it:

    NSMutableDictionary *rowData = [[self.results objectAtIndex:[indexPath row]] mutableCopy];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Array of NSDictionary objects. These Dictionaries are parsed from a JSON
I have 2 arrays. The first is an array of dictionaries from a JSON
I'm struggling with trying to sort an array of dictionaries. My dictionaries have a
I have an array of dictionaries loaded from a plist (below) called arrayHistory. <plist
I have a UITableView that was created from data coming from a mutable array.
I'm trying to display data from a plist that is an array of dictionaries:
I have an NSMutablearray, populated by dictionaries [from a JSON request] i need to
I have a JSON string (from PHP's json_encode() that looks like this: [{id: 1,
I have an array of dictionaries. I would like to extract an array with
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.