Message -indexOfObjectIdenticalTo:


#1

On page 323 where you play with TXT record there is a message -indexOfObjectIdenticalTo: sent to an array object. It is array of net services and on page 321 when you need to get a reference to an object from the same array you just use more familiar -indexOfObject: so I went and looked it up in the documentation and I still have no idea if these two methods are effectively the same or not, at least with arrays.

“-indexOfObjectIdenticalTo: - Objects are considered identical if their object addresses are the same.”
"-indexOfObject: - Objects are considered equal if isEqual: returns YES."

Did you use it just to make us aware of it or is there another reason?

Plus, a minor detail on page 324, method name is -netServiceDidResloveAddress:, but in text you refer to it as -netServiceDidReslove:


#2

The difference between the two methods is as follows:

indexOfObject: will loop thru the entire array and send the message isEquals: to each item in the array with the same argument passed to indexOfObject:.

indexOfObjectIdenticalTo: will loop through the entire array and do a simple pointer comparison for each item in the array with the same argument passed to indexOfObjectIdenticalTo:.

Now, NSObject implements isEquals: to do a simple pointer comparison. But, some subclasses of NSObject implement isEquals: to do something different. For example, NSString implements isEquals: to check for string equality.

So, for something like NSString, you have could have two instances that store the same string. indexOfObjectIdenticalTo: will fail if you compared these strings, but indexOfObject: would succeed. Usually, the documentation for a particular class tells you if they have overridden isEquals: to do something more than a pointer comparison.


#3

Was there a specific reason for using indexOfObjectIdentalTo: in the netServiceDidResolveAddress: method and indexOfObject in the other two methods? Was it just to show us a different method? Either method would work, right?