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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:45:32+00:00 2026-05-30T02:45:32+00:00

I am learning Objecive-C and try to removeObject method in loop. It is not

  • 0

I am learning Objecive-C and try to removeObject method in loop.
It is not work correctly. I recive “Thread 1: Program received signal:”SIGABRT”.” on that line.
What is wrong?

NSMutableArray *bookListMutable = [NSMutableArray arrayWithObjects:@"TitleM 2", @"TitleM 4", @"TitleM 5", nil];
[bookListMutable addObject:@"TitleM 3 added"];
[bookListMutable insertObject:@"TitleM 1 inserted" atIndex:0];

long countMutable;
countMutable = bookListMutable.count;


for(int y = 0; y < countMutable; y++){
    [bookListMutable removeObject:[bookListMutable objectAtIndex:y]];
}

P.S. xCode 4.1

  • 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-30T02:45:35+00:00Added an answer on May 30, 2026 at 2:45 am

    You should not remove items in that order. Let’s say the array has 4 items {0, 1, 2, 3} and simulate the execution of the program:

    1. First iteration with y = 0: removing item at index 0 from {0, 1, 2, 3} gives {1, 2, 3}.

    2. Second iteration with y = 1: removing item at index 1 from {1, 2, 3} gives {1, 3}

    3. Third iteration with y = 2: removing item at index 2 from {1, 3} gives. Oops, there is no item at index 2 => Exception.

    So you should iterate backwards like this:

    for(int y = countMutable-1; y >= 0; y--) {
        [bookListMutable removeAtIndex:y]];
    }
    

    or use the build in method:

    [bookListMutable removeAllObjects];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Work got in the way of learning Objective C but i'm back at it
Here is the method declaration midway in Apple's documentation: Learning Objective-C: A Primer -
Im learning objective C (using a mac in my work) In my house I
I'm learning Objective-C and using GNUStep, but when i try to execute my very
I'm learning Objective C to program on iOS. I know it has something to
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't
Is learning Objective-J worth it, considering the limited number of Objective-J tutorials? Also, what
I'm learning objective-c and keep bumping into the @ symbol. It is used in
I'm learning objective-C and Cocoa and have come across this statement: The Cocoa frameworks
I'm slowly learning Objective-C and Cocoa, and the only way I see so far

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.