• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Different Dictionaries
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Different Dictionaries


  • Subject: Re: Different Dictionaries
  • From: Óscar Morales Vivó <email@hidden>
  • Date: Wed, 14 Jul 2004 22:55:43 +0200

That sounds like NSDictionary is doing a shallow equality comparison, comparing the keys and the object pointers (instead of comparing the keys and the object contents). So your second dictionary, after saving and loading, has objects with the same contents but which are distinct objects from those in the first dictionary.

You can implement a deep comparison easily.

Hope that helps.

Sscar Morales Vivs.

On 14 Jul 2004, at 22:31, Lorenzo wrote:

Hi,
thanks for your prompt reply. But I think you lost a detail in my code.
I save an original dict to a file, then I immediately load that file in a
new dict and compare this new dict with the original dict, and they are
different! So that's strange. And even more strange, if I compare the string
descriptions of the two dicts, they are equal!

NSString *memString = [memDict description];
NSString *readString = [readDict description];

BOOL areEqual = [memString isEqualToString:readString];

Any idea?

Best Regards
--
Lorenzo
email: email@hidden

From: j o a r <email@hidden>
Date: Wed, 14 Jul 2004 19:07:52 +0200
To: Lorenzo <email@hidden>
Cc: email@hidden
Subject: Re: Different Dictionaries

Perform the equality test as stated in the documentation yourself, and
see where it fails:

==============================================================
Two dictionaries have equal contents if they each hold the same number
of entries and, for a given key, the corresponding value objects in
each dictionary satisfy the isEqual: test.
==============================================================

j o a r

On 2004-07-14, at 18.27, Lorenzo wrote:

I have some problem with the method isEqualToDictionary. It returns
that 2
dictionaries are different while indeed they should be equal.
I have one only dictionary called memDict.

[memDict writeToFile:path atomically:YES];
readDict = [NSDictionary dictionaryWithContentsOfFile:path];

if([memDict isEqualToDictionary:readDict]){
NSLog(@"Dictionaries are Equal");
}
else NSLog(@"Dictionaries are NOT Equal");


And I got always the log "Dictionaries are NOT Equal".
It seems that once saved to a file, the readDict dictionary written to
the
disk becames different. No matter if I use NSDictionary or
NSMutableDictionary.
So, how can I compare if the saved readDict is Equal to the memDict I
have
in memory? I need this in order to tell the user to save the changes.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Different Dictionaries (From: Lorenzo <email@hidden>)

  • Prev by Date: Re: applicationShouldTerminateAfterLastWindowClosed bug?
  • Next by Date: Re: Different Dictionaries
  • Previous by thread: Re: Different Dictionaries
  • Next by thread: Re: Different Dictionaries
  • Index(es):
    • Date
    • Thread