title: How can I use NSRange with integers to simplify my code?
body: <p>I've just started learning Objective-C and made a little compass app that will display a direction when it falls into a range of headings. It works just fine, but I wonder if there is a more concise way of writing it using <code>NSRange</code>. After a lot of looking, it seems like <code>NSRange</code> is used more for string functions rather than numbers. </p>
  
  <p>I tried to make an instance of <code>NSRange</code> my starting point to make this more concise, I couldn't track down the function that would find if a number falls within an <code>NSRange</code>.</p>
  
  <p>Am I on the right track here, or am I making this more verbose than it needs to be?</p>
  
  <p>Thanks in advance..</p>
  
  <p>Here was my failed jumping off point for attempting to shorten up the code:</p>
  
  <pre><code>// If heading falls within this range, then display "S" for south    
  NSRange eastenRange = NSMakeRange (80, 100); 
  NSRange southernRange = NSMakeRange (170, 190); 
  etc...
  </code></pre>
  
  <p>Here is my current code (works fine):</p>
  
  <pre><code>- (void)locationManager:(CLLocationManager *)manager 
      didUpdateHeading:(CLHeading *)newHeading
  {
   // Define and display the heading
   NSNumber *theHeading = [NSNumber numberWithInt:[newHeading trueHeading]];
   [headingLabel setText:[NSString stringWithFormat:@"%@°", theHeading]];
  
   // Define the range of directions
   NSNumber *northLowerRange = [NSNumber numberWithInt:10];
   NSNumber *northUpperRange = [NSNumber numberWithInt:350];
  
   NSNumber *eastLowerRange = [NSNumber numberWithInt:80];
   NSNumber *eastUpperRange = [NSNumber numberWithInt:100];
  
   NSNumber *southLowerRange = [NSNumber numberWithInt:170];
   NSNumber *southUpperRange = [NSNumber numberWithInt:190];
  
   NSNumber *westLowerRange = [NSNumber numberWithInt:260];
   NSNumber *westUpperRange = [NSNumber numberWithInt:280];
  
  
   // If the heading falls within the correct ranges, then display the direction
   if ([northLowerRange compare:theHeading] == NSOrderedDescending || [northUpperRange compare:theHeading] == NSOrderedAscending)
    [directionLabel setText:@"N"];
   else if ([eastLowerRange compare:theHeading] == NSOrderedAscending &amp;&amp; [eastUpperRange compare:theHeading] == NSOrderedDescending)
    [directionLabel setText:@"E"];
   else if ([southLowerRange compare:theHeading] == NSOrderedAscending &amp;&amp; [southUpperRange compare:theHeading] == NSOrderedDescending)
    [directionLabel setText:@"S"];
   else if ([westLowerRange compare:theHeading] == NSOrderedAscending &amp;&amp; [westUpperRange compare:theHeading] == NSOrderedDescending)
    [directionLabel setText:@"W"];
   else
    [directionLabel setText:@"-"];
  
  }
  </code></pre>