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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:43:31+00:00 2026-06-18T15:43:31+00:00

According to the NSMutableArray documentation : removeLastObject raises an NSRangeException if there are no

  • 0

According to the NSMutableArray documentation:

removeLastObject raises an NSRangeException if there are no objects in the array.

For some reason, I seem to be able to call this method on an empty array, and no exception is thrown.

Here’s a test case:

- (void)testNSMutableArray
{
    NSMutableArray* arr = [[NSMutableArray alloc] init];
    STAssertTrue([arr count] == 0, @"Array count should be 0");
    STAssertThrows([arr removeLastObject], @"Should throw NSRangeException");
}

This test case fails on the last line for me with the message:

[arr removeLastObject] raised (null). Should throw NSRangeException

Am I confused here? Is the documentation wrong?

  • 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-18T15:43:32+00:00Added an answer on June 18, 2026 at 3:43 pm

    Looking at the assembly, it appears this behaviour changed in Lion. Here’s a portion of the implementation of [__NSArrayM removeLastObject] (which is the actual implementation you’re calling):

    0x3494975a:  movs   r0, #7
    0x3494975c:  bl     0x3490c26c                ; _CFExecutableLinkedOnOrAfter
    0x34949760:  cbz    r0, 0x3494977c            ; -[__NSArrayM removeLastObject] + 60
    

    This calls CFExecutableLinkedOnOrAfter with a value of 7; if that returns 1 (which it does on my machine), you get the behaviour you’re seeing. If it returns 0, you get an exception.

    CFExecutableLinkedOnOrAfter is an undocumented function, but some snooping around suggests that it returns if the executable is linked after a particular version of Mac OS X. Some more snooping suggests that the value of 7 corresponds to 10.7.

    So, if you’re running Lion or later, you won’t get an exception. Sounds like a doc bug to me!

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

Sidebar

Related Questions

I've got an array of objects that I'm wanting to sort through according to
According documentation: System.Array.Sort<T> - sorts the elements in an entire System.Array using the System.IComparable
According to Best way to remove from NSMutableArray while iterating? , we can't remove
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django
According to this post , IDEA uses Osmorc to run OSGi frameworks. It, in
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
According to Hibernate documentation : After observing that arrays cannot be lazy , you
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
I have two NSMutableArrays with NSString and NSNumber objects, more specific: NSMutableArray * points;
I have an NSArray of UILocalNotification objects that I need to sort according to

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.