As per this post: Understanding NSString comparison it will give different results but when I tried this with different scenarios as mentioned below it gave me same result.
I just want to know when '==' and 'isEqualToString:" gives different results. For me it is giving same results.
I tried below mentioned ways:
NSString *str1 = @"Hello!";
NSString *str2 = @"Hello!";
if(str1 == str2){
}
if([str1 isEqualToString:str2]){
}
=================
NSString *str1 = [[NSString alloc] initWithString:@"Hello!"];
NSString *str2 = [[NSString alloc] initWithString:@"Hello!"];
if(str1 == str2){
}
if([str1 isEqualToString:str2]){
}
=================
ClassA *obj1 = [[ClassA alloc] initWithString:@"Hello!"];
ClassA *obj2 = [[ClassA alloc] initWithString:@"Hello!"];
// The above "initWithString:" is the custom initializer for ClassA.
if(obj1.str == obj2.str){
}
if([obj1.str isEqualToString:obj2.str]){
}
================
Each of the above ways gives me same result. As per I know till now '==' compares object reference and 'isEqualToString:' compare the values of the objects.
Any detail answer with example would be very helpful!