Tekkaman

导航

 

Determining Equality of Objects

  If you need to determine whether one object is the same as another object, it’s important to remember that you’re working with pointers. The standard C equality operator == is used to test equality between the values of two variables, like this:

  

  When dealing with objects, the == operator is used to test whether two separate pointers are pointing to the same object:

  

  If you need to test whether two objects represent the same data, you need to call a method like isEqual:, available from NSObject:

  

  If you need to compare whether one object represents a greater or lesser value than another object, you can’t use the standard C comparison operators > and <. Instead, the basic Foundation types, like NSNumber, NSString and NSDate, provide a compare: method:

  

  

posted on 2014-02-15 21:45  Tekkaman  阅读(234)  评论(0编辑  收藏  举报