• 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: Differences between -isEqual: and -isEqualTo:?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Differences between -isEqual: and -isEqualTo:?


  • Subject: Re: Differences between -isEqual: and -isEqualTo:?
  • From: Charles Srstka <email@hidden>
  • Date: Thu, 18 Sep 2008 17:15:11 -0500

On Sep 18, 2008, at 4:59 PM, Dave DeLong wrote:

IIRC, isEqual: compares memory addresses, whereas isEqualTo: compares hashes of the objects being compared. I also believe that isEqual: is the preferred method.

The documentation says that isEqual: checks the hashes, so that isn't it. Also:


#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSString *hello1 = @"Hello World";
    NSString *hello2 = [@"Hello " stringByAppendingString:@"World"];

NSLog(@"address of hello1: 0x%x address of hello2: 0x%x isEqual: %u isEqualTo: %u isEqualToString: %u",
hello1, hello2, [hello1 isEqual:hello2], [hello1 isEqualTo:hello2], [hello1 isEqualToString:hello2]);


    [pool drain];
    return 0;
}

[Session started at 2008-09-18 17:13:53 -0500.]
2008-09-18 17:13:53.809 isequaltest[2082:10b] address of hello1: 0x2030 address of hello2: 0x1063f0 isEqual: 1 isEqualTo: 1 isEqualToString: 1


The Debugger has exited with status 0.

According to the documentation, isEqualToString: is faster when you know both objects are strings. I'm not sure what isEqualTo: is for, though.

Charles
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Differences between -isEqual: and -isEqualTo:?
      • From: Rick Mann <email@hidden>
    • Re: Differences between -isEqual: and -isEqualTo:?
      • From: Ken Thomases <email@hidden>
References: 
 >Differences between -isEqual: and -isEqualTo:? (From: Rick Mann <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: Differences between -isEqual: and -isEqualTo:?
  • Next by Date: Re: Drawing an NSImage in a CALayer
  • Previous by thread: Re: Differences between -isEqual: and -isEqualTo:?
  • Next by thread: Re: Differences between -isEqual: and -isEqualTo:?
  • Index(es):
    • Date
    • Thread