title: argument isKindOfClass: [NSNumber class] - sane way to check this?
body: <p>So I was playing with something where the class type of the arg is unknown until runtime.
  like this:</p>
  <pre><code>- (NSNumber *)doWhatever:(id)arg
  {
      // this ALWAYS FAILS
      if ([arg isKindOfClass:[NSNumber class]]) {
          return arg;
      }
      else {
          // what was it???
          NSLog(&quot;arg klass=%@&quot;, [arg class]);  // prints NSCFNumber
      }
  
      // This check works correctly.
      if ([arg isKindOfClass:[NSArray class]]) {
          for (id x in arg) {
              NSNumber *result = [self doWhatever:x];
              if (result) {
                  return result;
              }
          }
      }
      return nil;
  }
  
  - (void)someMethod
  {
      NSArray *myArray = [NSArray arrayFromObjects:[NSNumber numberWithInt:3], nil]];
      NSNumber *myNum = [self doWhatever:myArray];
      NSLog(@&quot;myNum=%@&quot;, myNum);
  }
  </code></pre>
  <p>This is obviously a contrived example of what I'm trying to do.
  The point is this never works b/c the class of &quot;arg&quot; always appears as NSCFNumber, and I can't figure out a way to check for that.</p>
  <p>Any way to make it less confusing to detect whether an arbitrary value in an array is an integer or not?</p>
  <hr />
  <p><strong>UPDATE:</strong>
  Thanks @chuck, @omz, and @Nikita Leonov for your help.  What I posted here originally was just a simplification of the problem I was having and wrote it here without running it first.  That code once updated to remove the errors (see below) runs fine actually.</p>
  <p>The mistake I made in my real code that I was having trouble with was equally silly--I was passing the array back in to &quot;doWhatever&quot; instead of the item at array's index, which is why I was having problems.</p>
  <p>Thanks for trying to help, however misguided my question was.
  Sorry for wasting everybody's time!</p>
  <p>Corrected code that runs as desired:</p>
  <pre><code>
  - (NSNumber *)doWhatever:(id)arg
  {
      // this NOW WORKS
      if ([arg isKindOfClass:[NSNumber class]]) {
          return arg;
      }
      else {
          // what was it???
          NSLog(@"arg klass=%@", [arg class]);  // prints NSCFNumber
      }
      
      // This check works correctly.
      if ([arg isKindOfClass:[NSArray class]]) {
          for (id x in arg) {
              NSNumber *result = [self doWhatever:x];
              if (result) {
                  return result;
              }
          }
      }
      return nil;
  }
  
  - (void)someMethod
  {
      NSArray *myArray = [NSArray arrayWithObjects:
                          [NSNumber numberWithInt:1],
                          [NSNumber numberWithInt:2],
                          [NSNumber numberWithInt:3],
                          [NSNumber numberWithInt:4],
                          nil];
      NSNumber *myNum = [self doWhatever:myArray];
      NSLog(@"myNum=%@", myNum);
  }
  </code></pre>