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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:11:32+00:00 2026-05-30T08:11:32+00:00

I am using block based enumeration similar to the following code: [[[rows objectForKey:self.company.coaTypeCode] objectForKey:statementType]

  • 0

I am using block based enumeration similar to the following code:

[[[rows objectForKey:self.company.coaTypeCode] objectForKey:statementType] 
    enumerateObjectsWithOptions:NSEnumerationConcurrent 
                     usingBlock:^(id coaItem, NSUInteger idx, BOOL *stop) { 
// block code here
}]

I would like to remove some of the objects during the enumeration process depending on the their object values.

How could I do this? I know that manipulating an mutable array or dictionary (NSMutableArray or NSMutableDictionary) during enumeration is usually not possible.

What would be the best way to implement this?

Thank you!

  • 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-30T08:11:33+00:00Added an answer on May 30, 2026 at 8:11 am

    Since you can’t remove objects from an array or dictionary during enumeration, you’ll have to accumulate the items you want to delete, and then delete them all after the enumeration.

    If you’re dealing with an array, you can just accumulate the indices.:

    NSMutableIndexSet *indexesToDelete = [NSMutableIndexSet indexSet];
    NSUInteger currentIndex = 0;
    
    for (id obj in yourArray) {
        //do stuff with obj
        if (shouldBeDeleted(obj)) {
            [indexesToDelete addIndex:currentIndex];
        }
        currentIndex++;
    }
    
    [yourArray removeObjectsAtIndexes:indexesToDelete];
    

    Since the order of the keys in an NSDictionary is undefined, for an NSMutableDictionary you’ll have to accumulate keys instead:

    NSMutableArray *keysToDelete = [NSMutableArray array];
    
    for (id obj in [yourDictionary keyEnumerator]) {
        //do stuff with obj
        if (shouldBeDeleted(obj)) {
            [keysToDelete addObject:obj];
        }
    }
    
    [yourDictionary removeObjectsForKeys:keysToDelete];
    

    It’s the same thing if you’re enumerating with a block. Declare the enumerator in the same scope where you declare the block and it will be retained and just work.

    Also worth looking at this question from 3 years ago: Best way to remove from NSMutableArray while iterating?.

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

Sidebar

Related Questions

I seem to be using this block of code alot in Python. if Y
I have my app, using functionality that is based on unity application block. Sometimes
I'm using SQLite3, and the SQLite3 class that's built into PHP. The following code
How can I rotate an UIImageView 360 degrees using BLOCK-BASED animation? here is my
I'm creating a tile-based game and am using block rendering to update a large
I am using: jquery-1.6.2 jquery-ui-1.8.16 collision 1.0.1 ...to build a web-based block painting application.
I am trying to do something pretty basic here. I am using a block-based
I want to block a USB based on volume using C#. Like I want
I am looking for examples of configuration based validation using Validation Application Block. I've
in a using block for a connection to the entities, How am I to

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.