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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:55:19+00:00 2026-05-23T18:55:19+00:00

All, I have strings stored in a NSMutableArray. When a certain condition is met

  • 0

All,

I have strings stored in a NSMutableArray. When a certain condition is met elsewhere in the code, the object that is FIRST in the NSMutableArray (read, objectAtIndex:0) gets removed. After it is removed, I need to shift everything down an index. Here is my example:

/*
    Index/Value
    0 - one
    1 - two
    2 - three
    3 - four
    4 - five
    5 - six
    6 - seven
*/
//removes object...
[mArray removeObjectAtIndex:0];
//I am missing something here...


//I want the value of the array to be as follows:
/*
    Index/Value
    0 - two
    1 - three
    2 - four
    3 - five
    4 - six
    5 - seven
*/

What am I missing?

EDIT: The NSMutableArray is stored in NSUserDefaults. Is that what may be causing this not to work?

EDIT2: Because it is stored in NSUserDefaults, it changes to immutable. Check out the accepted answer for the correct way to do it. Details here: crashes my app [NSMutableArray1 removeAllObjects] iphone sdk

  • 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-23T18:55:20+00:00Added an answer on May 23, 2026 at 6:55 pm

    If I understand your issue correctly you are storing an NSMutableArray to NSUserDefaults and then when you load it out of NSUserDefaults it throws an error when you try to mutate?

    This is because when you retrieve the array from NSUserDefaults it will be an instance NSArray not NSMutableArray therefore you need to make a an instance of NSMutableArray to work with.

    NSMutableArray *mArray = [[NSMutableArray alloc] initWithArray:myArrayFromNSUserDefaults];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of 400 strings that all end in _GONOGO or _ALLOC.
I have a large amout of objects that all have a filename stored inside.
I have about thirty strings that get passed to my stored procedure which act
We have to build Strings all the time for log output and so on.
I have an array of strings: @array I want to concatenate all strings beginning
Does Python have a pool of all strings and are they (strings) singletons there?
I have a big ol' .po file containing all the user-facing strings I need
I have some data structures: all_unordered_m is a big vector containing all the strings
Specifically, I have an array of strings called val, and want to replace all
I have a string. How do I remove all text after a certain character?

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.