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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:57:56+00:00 2026-06-05T22:57:56+00:00

I have been working with NSArray s and NSMutableArray s that store NSDate objects

  • 0

I have been working with NSArrays and NSMutableArrays that store NSDate objects for a few days now. I noticed that calling [listOfDates removeObject:date1] removes all the NSDate objects from the array. I have instead been doing this to remove objects:

  NSMutableArray *dateList; // Has Dates in it
  NSDate *dateToRemove;     // Date Object to Remove
  __block NSUInteger indexToRemove;
  __block BOOL       foundMatch = NO;
  [dateList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([obj isEqualToDate:dateToRemove]) {
      indexToRemove = idx;
      foundMatch = YES;
      *stop = YES;
     }
  }];
  if (foundMatch) {
    [dateList removeObjectAtIndex:indexToRemove];
  }

Is there a better way to be doing this? Perhaps another data structure? Or a simpler function?

  • 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-05T22:57:58+00:00Added an answer on June 5, 2026 at 10:57 pm

    You should use the first method you tried:

    [listOfDates removeObject:date1];
    

    This will remove date1 and ONLY date1 from listOfDates. This should NOT remove all NSDate objects from listOfDates unless all NSDate objects in listOfDates are date1.

    You could also use removeObjectAtIndex: combined with indexOfObject: to product the same effect, but that’s extra code.

    From the NSMutableArray class reference for removeObject:

    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).

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

Sidebar

Related Questions

I have been working with Zend for a few months now and am at
I have been working with ASP.NET for a few years and am now working
I have been working on a site for about a week now and we
I have been working on a site that relies heavily on images, and so
I have been working on a Core Data iOS app that works perfectly through
Have been working on a Tower Defense game for iOS for some time now.
I have been working on a project that displays data in an XML file.
I have been working on a C++ project that links to a .so(dynamic library)
I have been working on a side project for the last few weeks, and
I have been working on an application in Xcode for a while now and

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.