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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:10:06+00:00 2026-06-11T10:10:06+00:00

Plist is copyed to documents directory if it doesn’t exist. If it already exists,

  • 0

Plist is copyed to documents directory if it doesn’t exist.

If it already exists, I want to use the “Name” key from NSDictionary in bundleArray to find the matching NSDictionary in documentsArray.

When the match is found, I want to check for changes in the strings and replace them if there is a change.

If a match is not found it means this dictionary must be added to documents plist.

This is my code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self managePlist];
return YES;
}

- (void)managePlist {

NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Objects.plist"];
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Objects" ofType:@"plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path]) {
    [fileManager copyItemAtPath:bundle toPath:path error:&error];

} else {

    NSArray *bundleArray = [[NSArray alloc] initWithContentsOfFile:bundle];
    NSMutableArray *documentArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

    BOOL updateDictionary = NO;
    for(int i=0;i<bundleArray.count;i++) {

        NSDictionary *bundleDict=[bundleArray objectAtIndex:i];

        BOOL matchInDocuments = NO;
        for(int ii=0;ii<documentArray.count;ii++)
        {
            NSMutableDictionary *documentDict = [documentArray objectAtIndex:ii]; 
            NSString *bundleObjectName = [bundleDict valueForKey:@"Name"];
            NSString *documentsObjectName = [documentDict valueForKey:@"Name"];
            NSRange range = [documentsObjectName rangeOfString:bundleObjectName options:NSCaseInsensitiveSearch];
            if (range.location != NSNotFound) {
                matchInDocuments = YES;
            }
            if (matchInDocuments) {

                if ([bundleDict objectForKey:@"District"] != [documentDict objectForKey:@"District"]) {
                    [documentDict setObject:[bundleDict objectForKey:@"District"] forKey:@"District"];
                    updateDictionary=YES;
                }
            }

            else {
                [documentArray addObject:bundleDict];
                updateDictionary=YES;
            }
        }
    }
    if(updateDictionary){
        [documentArray writeToFile:path atomically:YES];
    }

}

}

If I run my app now I get this message: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'

How can I fix this?

When this is fixed, do you think my code will work?

If not, I would be happy for some suggestions on how to do this. I have struggled for a while and really need to publish the update with the corrections! Thanks a lot for your help.

  • 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-11T10:10:07+00:00Added an answer on June 11, 2026 at 10:10 am

    Presumably the documentDict is actually immutable. Even though you assign it to an NSMutableDictionary, this doesn’t accurately describe the underlying data.

    NSMutableDictionary *documentDict = [documentArray objectAtIndex:ii];
    

    should be:

    NSMutableDictionary *documentDict = [NSMutableDictionary dictionaryWithDictionary:[documentArray objectAtIndex:ii]];
    

    and wherever you edit the documentDict, add:

     [documentArray replaceObjectAtIndex:ii withObject:documentDict];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My plist array of dictionaries is copied from the bundle to the documents directory
I have a custom plist: <key>Ford</key> <dict> <key>name</key> <string>Ford</string> <key>color</key> <string>green</string> <key>price</key> <integer>45000</integer> </dict
I use the following code to copy a Resources plist file into the documents
I've created a plist. I want to use a UIsegmentedControl with 3 sections. Each
I created a plist that contains an NSDictionary structure. The key is a label
So I have a plist structured string, that get dynamically (not from the file
I'm trying to add the item <key>UIStatusBarHidden</key><true/> to my plist that's auto-generated by CMake.
I created a plist and the structure looks like: Root - NSDictionary firstName -
I have a plist file in my main app bundle that I want to
I have a plist that I want to auto-populate the version number of the

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.