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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:27:13+00:00 2026-05-29T10:27:13+00:00

I am using one NSMutableArray with same string object. Here is the code NSMutableArray

  • 0

I am using one NSMutableArray with same string object.

Here is the code

NSMutableArray *arr = [[NSMutableArray alloc]initWithObjects:@"hello",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",nil];
NSObject *obj = [arr objectAtIndex:2];    
[arr removeObject:obj];       
NSLog(@"%@",arr);

When i try to remove 3rd object of array, its removing all object with “hi” string.
I am not getting why its happening.
my doubt is while removing object, NSMutableArray match string or address.

  • 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-29T10:27:14+00:00Added an answer on May 29, 2026 at 10:27 am

    It’s because you’re using removeObject which removes all objects that are “equal” to the one you pass in. As per this Apple documentation:

    This method uses indexOfObject: to locate matches and then removes
    them by using removeObjectAtIndex:. Thus, matches are determined on
    the basis of an object’s response to the isEqual: message. If the
    array does not contain anObject, the method has no effect (although it
    does incur the overhead of searching the contents).

    You’re seeing the effects of literal strings here where each of those @"hi" objects will turn out to be the same object just added many times.

    What you really want to do is this:

    NSMutableArray *arr = [[NSMutableArray alloc]initWithObjects:@"hello",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",@"hi",nil];
    [arr removeObjectAtIndex:2];
    NSLog(@"%@",arr);
    

    Then you’re specifically removing the object at index 2.

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

Sidebar

Related Questions

i have one problem when i sort the NSMutablearray using date and time wise.
I am using one of snook.ca script for simple slideshow. Here it is in
I'd like to split a string using one or more separator characters. E.g. a
I am developing one application. In that iam using the NSMutableArray for storing the
I am using distributed object for inter process communication. I am running one server
I have a NSMutableArray of QuoteMap objects. When I add one using the below
Possible Duplicate: Obj-C, how can I append one NSMutableArray to another? I want to
How does one resort an NSMutableArray using an index? I would like to take
I have a very strange error using NSMutableArray in cocos2d/xcode In my code, I
When using one's own iPhone for development it's easy enough to access any crash

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.