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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:20:18+00:00 2026-06-09T22:20:18+00:00

I have an NSMutableArray that will start with 0 objects in it, but as

  • 0

I have an NSMutableArray that will start with 0 objects in it, but as the program progresses objects will be added to it. How can I shift all elements down, when a new element is added?

For example:

1) NSMutableArray array = 0 elements

2) NSMutableArray array = 1 element { [0,a]}

3) NSMutableArray array = 2 elements {[0, b], [1,a]}

4) NSMutableArray array = 3 elements {[0,c],[1,b],[2,c]}

As can be seen through the above list as objects are added to the array, all current elements move down. However, I do not want my array to exceed a certain size (lets say 10 elements). When a element is pushed to 11 I want it “pushed” out of the array. How can I go about doing this?

Similar questions: NSMutablearray move object from index to index

  • 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-09T22:20:20+00:00Added an answer on June 9, 2026 at 10:20 pm

    You can do that like this:

    [array insertObject:object atIndex:0];
    if ([array count] > 10) {
        [array removeLastObject];
    }
    

    The first line will automatically push the other elements out of the way, and the next bit just makes sure the array’s length never exceeds 10.

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

Sidebar

Related Questions

If I create an NSMutableArray that might have up to 2^16 elements, but will
I have an NSMutableArray that is populated with objects of strings. For simplicity sake
I have been working with NSArray s and NSMutableArray s that store NSDate objects
I have a NSMutableArray and a NSArray . Both consist of elements that are
I have this NSMutableArray which is a collection of objects that are being moved
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
I have a NSMutableArray that I need to search for a string and return
I have a NSMutableArray (called listOfSites) that is created and used in classA.m. I
I have an NSMutableArray called message that I've alloc'd in init and release in
I have a class that has a method: -(NSInteger) getCityCountForState:(NSString *)state CityArray:(NSMutableArray *)cityArray {

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.