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 9141849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:41:59+00:00 2026-06-17T09:41:59+00:00

My problem is that I have a class property that is of type NSMutableArray

  • 0

My problem is that I have a class property that is of type NSMutableArray, as defined in my header file, yet when I attempt to modify one of the array elements (an NSDictionary) I receive the following runtime error:

2013-01-16 14:17:20.993 debtaculous[5674:c07] * Terminating app due
to uncaught exception ‘NSInternalInconsistencyException’, reason:
‘-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent
to immutable object’

Header declaration:

//  BudgetViewController.h

#import <UIKit/UIKit.h>

@interface BudgetViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
- (IBAction)afterTaxIncomeEditingDidEnd:(id)sender;
@property (strong, nonatomic) NSMutableArray *budgetArray;
@property (strong, nonatomic) IBOutlet UITextField *afterTaxIncome;
@property (strong, nonatomic) IBOutlet UITableView *budgetTableView;

@end

Method that generates the error:

-(void)applyCCCSWeights
{
    NSMutableDictionary *valueDict;
    NSString *newAmount;

    for (id budgetElement in [self budgetArray]) {
        valueDict = [[NSMutableDictionary alloc] initWithDictionary:budgetElement];
        newAmount = [NSString stringWithFormat:@"%0.2f", [[self afterTaxIncome].text floatValue] * [[budgetElement objectForKey:@"cccs_weight"] floatValue]];
        [valueDict setValue:newAmount forKeyPath:@"amount"];

        [[self budgetArray] replaceObjectAtIndex:0 withObject:valueDict];
        NSLog(@"%0.2f (%0.2f)", [[budgetElement objectForKey:@"amount"] floatValue], [[self afterTaxIncome].text floatValue] * [[budgetElement objectForKey:@"cccs_weight"] floatValue]);
    }

    [self.budgetTableView reloadData];
}

// Note the replaceObjectAtIndex:0 above is just a placeholder. This will be replaced with the correct index.

  • 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-06-17T09:42:00+00:00Added an answer on June 17, 2026 at 9:42 am

    In your init method, put this:

    budgetArray = [[NSMutableArray alloc] init];
    

    Also, why not use dictionary and array literal syntax?

    -(void)applyCCCSWeights {
        NSMutableDictionary *valueDict;
        NSString *newAmount;
    
        for (NSDictionary *budgetElement in [self budgetArray]) {
            valueDict = [budgetElement mutableCopy];
            newAmount = [NSString stringWithFormat:@"%0.2f", [[self afterTaxIncome].text floatValue] * [budgetElement[@"cccs_weight"] floatValue]];
            valueDict[@"amount"] = newAmount;
    
            _budgetArray[0] = valueDict;
            NSLog(@"%0.2f (%0.2f)", [budgetElement[@"amount"] floatValue], [[self afterTaxIncome].text floatValue] * [budgetElement[@"cccs_weight"] floatValue]);
        }
    
        [self.budgetTableView reloadData];
    }
    

    Notice that [[self budgetArray] replaceObjectAtIndex:0 withObject:valueDict];

    becomes: _budgetArray[0] = valueDict;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the problem that my view controller class has too many delegates and
I have a class that is mapped to a table using NHibernate. The problem
i have a problem calling multiple instance of a class that i have coded
I am facing a problem. I have a Class that extends listactivity and its
Problem in words: For my application, I have a class that reads from a
Today I ran into the following problem with NUnit. I have a class, that
I have a SimpleProducerConsumer class that illustrates a consumer/producer problem (I am not sure
My problem: require_once '/includes/aws-sdk-1.5.2/sdk.class.php'; My environment: I have a pretty standard PHP site that
I have a class Notification that implements the NSCoding protocol. I have an array
I have a base class ReportElement which has type property: public abstract class ReportElement

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.