Skip to content

December 9, 2011

Compare objects in Cocoa

by noise

Next example shows you how to compare objects in Cocoa. Do not use == for objects comparison, use isEqual method, or method variation.

Next example shows how to compare two strings in Objective C:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
    @autoreleasepool {
        NSString *string1 = @"justAString";
        NSString *string2 = @"justAString";
        if ( [string2 isEqualToString:string1] )
            NSLog(@"Strings are equal");
            NSLog(@"Strings are not equal");
    return 0;
Read more from Cocoa

Leave a Reply


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments