title: Objective C isEqual not evaluating when comparing int and id
body: <p>I am trying to implement binary search in Objective C. I am mainly struggling with this line of code <code>if ([searchItem isEqual:midElement]){</code> because it's evaluating to be true when the values are different <code>searchItem = 1</code> and <code>midElement = 4</code>:</p>
  
  <pre><code>@implementation NSArray (BinarySearch)
  
  - (NSInteger) binarySearch : (id) searchItem {
      NSLog(@"SearchItem: %@", searchItem);
      return [self binarySearch:searchItem min:0 max:[self count] - 1];
  }
  
  - (NSInteger) binarySearch:(id)searchItem min:(NSInteger)min max:(NSInteger)max {
      if (max &lt; min) {
          return NSNotFound;
      }
  
      NSInteger mid = (max + min) / 2;
      id midElement = [self objectAtIndex:mid];
      NSLog(@"Search Item: %d, Current Value: %@, Min: %d, Mid: %d, Max: %d", searchItem, midElement, min, mid ,max);
  
      NSLog(@"IsEqual: %d", [searchItem isEqual:midElement]);
  
  
      if ([searchItem isEqual:midElement]){
          return mid;
      }
      else if (searchItem &lt; midElement){
          return [self binarySearch:searchItem min:min max:mid];
      }
      else{
          return [self binarySearch:searchItem min:mid max:max];
      }
  }
  
  @end
  
  int main(int argc, const char * argv[]) {
      @autoreleasepool {
          NSArray *orderedList = @[@1, @2, @4, @7, @8, @10];
          NSLog(@"Binary search on a list: %d", [orderedList binarySearch: 1]);
      }
      return 0;
  }
  </code></pre>
  
  <p>Code output:</p>
  
  <pre><code>SearchItem:
  Search Item: 1, Current Value: 4, Min: 0, Mid: 2, Max: 5
  IsEqual: 1
  Binary search on a list: 2
  Program ended with exit code: 0 
  </code></pre>
  
  <p>Edit for Genecode, when I changed it to this:</p>
  
  <pre><code>NSInteger mid = (max + min) / 2;
  int midElement = [self objectAtIndex:mid];
  NSLog(@"Search Item: %d, Current Value: %@, Min: %d, Mid: %d, Max: %d", searchItem, midElement, min, mid ,max);
  
  NSLog(@"IsEqual: %d", searchItem == midElement);
  
  
  if (searchItem == midElement){
      return mid;
  }
  </code></pre>
  
  <p><code>searchItem == midElement</code> evaluates to zero no matter what. Code output: </p>
  
  <pre><code>SearchItem:
  Search Item: 1, Current Value: 4, Min: 0, Mid: 2, Max: 5
  IsEqual: 0
  Search Item: 1, Current Value: 2, Min: 0, Mid: 1, Max: 2
  IsEqual: 0
  Search Item: 1, Current Value: 1, Min: 0, Mid: 0, Max: 1
  IsEqual: 0
  Binary search on a list: -1
  </code></pre>