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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:12:44+00:00 2026-06-17T10:12:44+00:00

I have an array and as I iterate through the array I wanted to

  • 0

I have an array and as I iterate through the array I wanted to replace the item as well. Is this not possible and will cause crahes if I do so? Here’s the code:

for (int i = 0; i < [highlightItemsArray count]; i++){
   //replace the from array with the new one
   NSMutableDictionary *tempDictionary = [NSMutableDictionary dictionaryWithDictionary:highlightItem];
   [tempDictionary setObject:[newHighlightItem objectForKey:@"from"] forKey:@"from"];
   [highlightItemsArray replaceObjectAtIndex:i withObject:tempDictionary];
   [indexes addIndex:i];
}

just wanted to know if this is legit in objective-C? if not then what is the alternative of doing so?

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

    You above code look good.

    If it crashes it is not due to altering of your array.

    However in old style loops ( while, for(;;), dowhile ) you can change any of these
    1. initialiser (but this is executed just once)
    2. counter
    3. condition.

    But in case of fast enumeration you can not do all these.

    Therefore if you incorporate your above code with for(… in …) it will throw an error, saying trying to mutate an immutable object. Even though you define your counter and/or array immutable fast enumeration treats them as immutable.

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

Sidebar

Related Questions

I have an array of Objects (file list excatly). How to iterate through this
I have an array list: private ArrayList<PerfStatBean> statFilterResults; I want to iterate through it
This is probably a simple question, but how do you iterate through an array,
I have an array that I would like to iterate through with a for
How do I iterate through a PHP array in jQuery? I have an array
I have 2 array lists. i iterate through list1 and store the data that
This script is supposed to to get a multidimensional array and iterate through the
I have an array of strings which when I iterate through and print its
Hi I have an array of dynamic type which i want to iterate through.
I have an array of images and then I iterate through each using $.each

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.