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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:06:26+00:00 2026-06-03T15:06:26+00:00

I stored an object under one NSDate key in an NSDictionary . I then

  • 0

I stored an object under one NSDate key in an NSDictionary. I then got another NSDate with the same date value and used it to retrieve the object from the NSDictionary. To my surprise, it returned nil. But what was revealed during my debug session blew my mind even more:

(lldb) po when
(NSDate *) $34 = 0x0f8be100 2012-05-11 21:08:37 +0000
(lldb) po [newTaskDict objectForKey:when]
(id) $36 = 0x00000000
(lldb) po [newTaskDict allKeys]
(id) $37 = 0x0f8c1650 <__NSArrayI 0xf8c1650>(
2012-05-11 21:08:37 +0000
)
(lldb) po [[newTaskDict allKeys] lastObject]
(id) $38 = 0x0f8b5ff0 2012-05-11 21:08:37 +0000
(lldb) p (int)[[[newTaskDict allKeys] lastObject] isEqual:when]
(int) $39 = 0
(lldb) po [[[newTaskDict allKeys] lastObject] class]
(id) $40 = 0x3f4496b0 __NSDate
(lldb) po [when class]
(id) $41 = 0x3f4496b0 __NSDate
(lldb) p (int)[[[newTaskDict allKeys] lastObject] isEqualToDate:when]
(int) $42 = 0
(lldb) p (int)[[[newTaskDict allKeys] lastObject] hash]
(int) $43 = 358463317
(lldb) p (int)[when hash]
(int) $44 = 358463317

As you can see, newTaskDict has only one entry keyed by the original NSDate whose value is($38):
0x0f8b5ff0 2012-05-11 21:08:37 +0000
and whose hash is($43):
35846331

The other NSDate I used to retrieve the entry is($34):
0x0f8be100 2012-05-11 21:08:37 +0000
and its hash is($44):
358463317

Aren’t these two NSDate exactly the same except for their memory addresses? How could isEqual:($39) and isEqualToDate:($42) return NO for them?

Solved:
This odd unequelness turned out to be caused by sub-second differences. You must read my second comment under the accepted answer because it is really interesting and it might bite you someday if you don’t know it.

  • 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-03T15:06:28+00:00Added an answer on June 3, 2026 at 3:06 pm

    isEqualToDate: will also look at the milliseconds, which you cannot see by logging the object since the description method of NSDate only formats a human friendly string, however there is more information behind the date object.

    It would seem your two dates are slightly different, this can happen even if they were created on the same run loop, try to create one and use just one object in 2 references, and then a second test to check two NSDate objects created separately – even one after the other, they should not be equal.

    to Quote Apple documentation:

    This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use timeIntervalSinceDate: to compare the two dates.

    https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/nsdate_Class/Reference/Reference.html

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

Sidebar

Related Questions

How do I print the value stored in BIO object time. Basically I need
Assuming I have a JQuery object stored in $e obtained through this selector: var
I have a an object stored in the model called domain, which has two
Can any object be stored in a DOM Storage ? When I do the
I have 2 different object types stored in RavenDb, which are a parent/child type
I have a Java enum with an object reference stored in a field. How
I'm using SqlClient.SqlCommand object to run a few stored procs on my db. Normally
I am trying to call the stored procedure using subsonic and getting Object Reference
I have a one-to-one unidirectional relationship between a Booking object and an Address object
Did any one encountered a scenario where application under high memory allocation load performed

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.