Object equivalence and same value
1. When the same value is stored in two different instance objects, it is called "same value ".
2. If the two instances are identical, they are called "equivalent ".
// Determine whether two instance objects are equivalent directly using the "=" Operator
Id objA, objB;
ObjA = @ "ggggggg ";
ObjB = objA;
If (objA = objB ){
NSLog (@ "objA is equivalent to objB ");
}
// The NSObject class provides a general method for determining the same value, called isEqual. The specific example is as follows:
NSArray * a1 = [NSArray arrayWithObjects: @ "one", @ "two", @ "three", @ "four", nil];
NSArray * b1 = [NSArray arrayWithObjects: @ "one", @ "two", @ "three", @ "four", nil];
If (a1 = b1 ){
NSLog (@ "YES ");
}
Else {
NSLog (@ "NO"); // The result is NO.
}
BOOL res;
Res = [a1 isEqual: b1];
NSLog (@ "a1 and b1 Same Value % d", res); // The result is YES.
Summary:
In addition to the isEqual: method provided in the root NSObject class, the NSString also provides the method named isEqualToString. We recommend that you use the latter when comparing two objects.