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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:37:24+00:00 2026-05-24T18:37:24+00:00

we are trying to add objects to an array , and when its full(

  • 0

we are trying to add objects to an array , and when its full( capacity=10) , to shift all the values forward and erase the first (such as shift register)

i was trying to do the next and it allways crash after 10, because 9 beyond bounds of 8..??

if (count>9)
{

    for(count=0;count<9;count++)    
    {
            NSLog(@"%@",listOfEvents);
        [listOfEvents removeObjectAtIndex:count];
        [listOfEvents insertObject:[listOfEvents objectAtIndex:(count+1)] atIndex:count];

    }
    [listOfEvents removeObjectAtIndex:9];   
    [listOfEvents insertObject:event atIndex: 9];       
}


else
        [listOfEvents addObject:event];

count++;

when i have tried without removing object ,i get another error .
what am i doing wrong?
why cant i add values to some index, when there is a space index befor him? ?
thanks a lot .

  • 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-24T18:37:25+00:00Added an answer on May 24, 2026 at 6:37 pm

    You don’t actually have to do it this way, since NSArray will perform the “downsliding” of elements on its own:

    To fill the gap, all elements beyond index are moved by subtracting 1 from their index.

    (NSMutableArray)

    So

    if (count > 9) [array removeObjectAtIndex: 0];
    [array addObject: newObject];
    

    should be sufficient. NSMutableArray behaves more like an ArrayList in Java, or a List in C#, and less like a plain C array.

    • 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 that I'm trying to add to the Items
From my understanding Sizzle returns an array of objects (DOMElements), I am trying to
I'm trying to add random numbers onto the end of this array when ever
I'm trying to make an array of objects in random, non repeating order. Using
I am trying to add a draggable object to to a simple html page.
I am trying to add the datetime object of a person. Whenever the birth
I am trying to add time to a Date object in javascript but am
I'm trying to add a unittest attribute to an object in Python class Boy:
I have been trying to add to the Watch window a Java Date object
I'm trying add a tab to my web page that looks like this: Using

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.