• 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: isEqualToArray: returning NO for equal arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isEqualToArray: returning NO for equal arrays


  • Subject: Re: isEqualToArray: returning NO for equal arrays
  • From: "Marc Wan" <email@hidden>
  • Date: Fri, 3 Nov 2006 09:24:02 +0800

On 11/3/06, Rosyna <email@hidden> wrote:

I've got two equal arrays that contain an array of dictionaries containing two objects each (an NSDate and an NSString).

If I compare them with isEqualToArray:, they're marked as not equal.
However, if I iterate the arrays and compare the dictionaries with
isEqualToDictionary: none of them are considered to be unequal. I
don't get it.... Why is isEqualToArray: returning NO (the last 0
after the output of each array)?



NSDictionary isEqualToDictionary checks to see if the two dictionaries have similar VALUES for similar KEYS. These values are nearly always actually in separate objects: [NSString stringWithString: @"Poisson"] and [NSString stringWithString: @"Poisson"] have similar values, but are different Objective-C objects.

 NSArray isEqualToArray compares two arrays to see if the values are the
same by using the isEqual method.  I'm not 100% sure here how deep/rich the
Foundation Framework is, but I would suspect that the problem is that the
NSDictionary isEqual method only returns TRUE/YES if they're actually the
same object (which is why they implemented the isEqualToDictionaryMethod).
Somewhere there, a method is comparing object pointers and not the
underlying values.

 That'd be what I'd investigate first.

 If you know they're both holding nsdictionaries, the simple fix, of course
is:

- (BOOL)isArray1: (NSArray *)arr1 equalToArray2: (NSArray *)arr2
{
 int i;

 for (i = 0; i < [arr1 count]; i++)
 {
   if (i < [arr2 count])
   {
     if (![[arr1 itemAtIndex: i] isEqualToDictionary: [arr2 itemAtIndex:
i]])
       return NO;
   }
   else
     return NO;
 }
 return YES;
}



 good ruck!
 marc.


Sincerely,
Rosyna Keller
Technical Support/Carbon troll/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People

It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: isEqualToArray: returning NO for equal arrays
      • From: Rosyna <email@hidden>
  • Prev by Date: Re: Pointers and NSImages
  • Next by Date: Re: isEqualToArray: returning NO for equal arrays
  • Previous by thread: isEqualToArray: returning NO for equal arrays
  • Next by thread: Re: isEqualToArray: returning NO for equal arrays
  • Index(es):
    • Date
    • Thread