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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:52:16+00:00 2026-06-17T14:52:16+00:00

Below is my code. NSMutableArray *arr = [[NSMutableArray alloc] init]; [arr addObject:@5]; [arr addObject:@7];

  • 0

Below is my code.

NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:@"5"];
[arr addObject:@"7"];
[arr addObject:@"8"];
[arr enumerateObjectsUsingBlock:^(NSString *obj,NSUInteger idx,BOOL *stop) {
        [arr replaceObjectAtIndex:idx withObject:@"10"];
}];

The Exception log I got

 *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x742a580> was mutated while being enumerated.'
*** First throw call stack:
(0x1596012 0x12a3e7e 0x161ecc5 0x158fe1b 0x158fa16 0x158f925 0x2ba4 0x1e87b7 0x1e8da7 0x1e9fab 0x1fb315 0x1fc24b 0x1edcf8 0x25f8df9 0x25f8ad0 0x150bbf5 0x150b962 0x153cbb6 0x153bf44 0x153be1b 0x1e97da 0x1eb65c 0x29fd 0x2925)
libc++abi.dylib: terminate called throwing an exception

The code is working fine while I am using for loop

for (int i = 0 ; i<  arr.count; i++) {
    [arr replaceObjectAtIndex:i withObject:@"8"];
}

So while I am using enumerateObjectsUsingBlock then I am getting exception. But both are enumerations. Right ? Then why upper code is giving was mutated while being enumerated exception?

  • 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-17T14:52:17+00:00Added an answer on June 17, 2026 at 2:52 pm

    Because your logic is flawed. It is not permited to mutate a collection during enumeration. And in the latter case, NSMutableArray doesn’t know you’re trying to emumerate it, only in the first case. And then it complains, since this is a semantic error. You should generally solve these kinds of problems by mutable copying the array and mutating the copy, then replacing the original one by the updated copy.

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

Sidebar

Related Questions

I have a simple code: NSMutableArray *arrayCheckList = [[NSMutableArray alloc] init]; [arrayCheckList addObject:[NSMutableDictionary dictionaryWithObjects:[NSArray
Below is my code: First Category.h #import <Foundation/Foundation.h> @interface Category : NSObject { NSMutableArray
I am using below code to add strings to NSMutableArray . But the issue
hi all according to below code i am trying to uploading the NSMutableArray items
I have the following code below to populate an array with images: NSString *fileName;
I'm having some troubles with the code below: NSSortDescriptor *idDescriptor = [[[NSSortDescriptor alloc] initWithKey:key
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
Below code not work, but it's work fine for jsf1.2. Now the framework is
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
below code is my databasehandler class i got it from a tutorial. Beside that

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.