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

  • Home
  • SEARCH
  • 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 8142615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:52:29+00:00 2026-06-06T12:52:29+00:00

I have an NSMutableArray which I assign with: NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:self.currentScene.elements,

  • 0

I have an NSMutableArray which I assign with:

NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:self.currentScene.elements, nil];
//selectedElement is assigned somewhere above this, shouldn't be relevant since it's the same object as the one in the array
int indexToRemove = [self.currentScene.elements indexOfObject:selectedElement];

I’m removing selectedElement from this array, but seeing some bizarre behaviour in the debugger. After initializing the array, by setting a breakpoint before removing selectedElement, I see this:

po newElements
(NSMutableArray *) $2 = 0x08c74e90 <__NSArrayM 0x8c74e90>(
<__NSArrayM 0x8c52e60>(
<StoryTextElement: 0x12ac6e00>,
<StoryTextElement: 0x8ca1a50>
)

)

(lldb) po selectedElement
(StoryElement *) $3 = 0x08ca1a50 <StoryTextElement: 0x8ca1a50>

I;m trying to remove the object with with:

NSLog(@"count: %d", [newElements count]); // prints count: 1
[newElements removeObject:selectedElement];
NSLog(@"count: %d", [newElements count]); // prints count: 1
[newElements removeObjectAtIndex:indexToRemove];  // throws an exception. indexToRemove is 1 in the debugger
NSLog(@"count: %d", [newElements count]);

I don’t understand why my object isn’t removed. It’s like I’m missing the point.

  • 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-06T12:52:32+00:00Added an answer on June 6, 2026 at 12:52 pm

    You have an array that contains one object, which is another array. newElements only has one valid index, and that is 0. You need to change your first line to look like

    NSMutableArray *newElements = [[self.currentScene.elements mutableCopy] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have an NSMutableArray which is loaded from file: searchTermsArray = [[NSMutableArray alloc]
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort
I have a Singleton which has an NSMutableArray containing a Class, the Class contains
I have a NSMutableArray: NSMutableArray *temp = //get list from somewhere. Now there is
I have a NSMutableArray and a NSArray . Both consist of elements that are
I have an NSMutableArray called message that I've alloc'd in init and release in
I have NSMutableArray day which contain (6 NSMutable arrays) arrays contain class Lesson{ NSString
I have a NSMutableArray which contains a few NSString objects. How can I test
Please help me i have a NSMutableArray which contains data until viewDidLoad is finished.

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.