title: Finding the lowest NSInteger from NSArray
body: <p>I am trying to return the lowest number in an array.</p>
  
  <p>Parameter: arrayOfNumbers - An array of NSNumbers.</p>
  
  <p>Return: The lowest number in the array as an NSInteger.</p>
  
  <p>The code I have thus far doesn't give me any errors, but does not pass the unit tests. What am I doing wrong?</p>
  
  <pre><code>- (NSInteger) lowestNumberInArray:(NSArray *)arrayOfNumbers {
  
      NSNumber* smallest = [arrayOfNumbers valueForKeyPath:@"@min.self"];
      for (NSInteger i = 0; i &lt; arrayOfNumbers.count; i++) {
          if (arrayOfNumbers[i] &lt; smallest) {
              smallest = arrayOfNumbers[i];
          }
      }
  
      NSInteger smallestValue = [smallest integerValue];
      return smallestValue;
  
  }
  </code></pre>
  
  <p>This is the unit test:</p>
  
  <pre><code>- (void) testThatLowestNumberIsReturned {
      NSInteger lowestNumber = [self.handler lowestNumberInArray:@[@3, @8, @-4, @0]];
      XCTAssertEqual(lowestNumber, -4, @"Lowest number should be -4.");
  
      lowestNumber = [self.handler lowestNumberInArray:@[@83, @124, @422, @953, @1004, @9532, @-1000]];
      XCTAssertEqual(lowestNumber, -1000, @"Lowest number should be -1000.");    
  }
  </code></pre>