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

  • Home
  • SEARCH
  • 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 601639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:44:14+00:00 2026-05-13T16:44:14+00:00

I have a plist. It has several dozen keys, each with NSMutableArray items: …

  • 0

I have a plist. It has several dozen keys, each with NSMutableArray items:

...
<key>KeyName1</key>
<array>
    <string>String1</string>
    <string>String2</string>
    <string>String3</string>
</array>

<key>KeyName2</key>
<array>
    <string>String1</string>
    <string>String2</string>
    <string>String3</string>
</array>
...

I have need to remove “String1” for all keys. This is the function that I wrote:

void DeleteString(NSString *StringToDelete){
NSMutableDictionary *item=nil;  

item = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];   

for (id obj in item){
    NSString *removeThisObject=(NSString *)obj;
    NSArray *ObjectArray = [item objectForKey:obj];

    for (int i = 0; i< [ObjectArray count]; i++){
        NSString *objectString = [ObjectArray objectAtIndex:i];

        if([objectString isEqualToString:StringToDelete]){              
            NSLog(@"Remove This from Item Dictionary: %@",removeThisObject);

            [item removeObjectForKey:obj];          
        }
    }

}
[item writeToFile:filePath atomically: YES];
[item release]; 

}

I figured it’d be easier to remove just the entire key if it includes a value that I do not want, but the line: [item removeObjForKey:obj] throws a EXC_BAD_ACCESS.

This does not make sense to me because, as I understand it EXC_BAD_ACCESS means that a message was sent to a released method.

Here, ‘item’ isn’t released is it? I have no error releasing ‘item’ just a few lines lower.

What is going on here? Is there a better way to remove “String1” from both Keys?

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-13T16:44:15+00:00Added an answer on May 13, 2026 at 4:44 pm

    It’s not because item is not released, but item is immutable.

    Within a for-in loop, the iterator that’s being traversed cannot be changed. If you do, the program will throw a mutated enumeration exception.

    You could

    • gather all obj into a separate array, then -removeObjectsForKeys: at the end of the loop; or
    • iterate on a copy of keys of the items. Specifically, for (id obj in [item allKeys]).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a plist file which is an array of dictionaries. Where each dictionary
I have a plist that has an array of dicts. in the dict there
Hey I have made up a plist file that has an array of strings
I have an array that has 500 objects, each object is nessisary because each
I have an NSArray of NSDictionaries each of which has 4 key values. I'm
I have a plist with root of type dictionary containing keys of type array,
I have set up a UITableView-based app, which has a .plist for holding the
I have a plist (array of dictionaries) which populates a table view and works
I have a plist uploaded on a server. When I log the array with:
I have a plist which contains an array of NSDictionary 's which represent a

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.