title: How to check if NSString format contains the same number of specifiers as there are variadic arguments?
body: <p>To ensure that a formatted string returned by <code>NSString initWithFormat:arguments:</code> is as expected, I need to determine if there are the same number of format specifiers as arguments. Below is a (slightly contrived and highly edited) example:</p>
  
  <pre><code>- (void)thingsForStuff:(CustomStuff)stuff, ...
  {
      NSString *format;
      switch (stuff)
      {
          case CustomStuffTwo:
              format = @"Two things: %@ and %@";
          break;
  
          case CustomStuffThree:
              format = @"Three things: %@, %@, and %@";
          break;
  
          default:
              format = @"Just one thing: %@";
          break;
      }
  
      va_list args;
      va_start(args, method);
      // Want to check if format has the same number of %@s as there are args, but not sure how
      NSString *formattedStuff = [[NSString alloc] initWithFormat:format arguments:args];
      va_end(args);
  
      NSLog(@"Things: %@", formattedStuff);
  }
  </code></pre>
  
  <p>Using this method, <code>[self thingsForStuff:CustomStuffTwo, @"Hello", @"World"]</code> would log</p>
  
  <blockquote>
    <p>"Two things: Hello and World"</p>
  </blockquote>
  
  <p>...but <code>[self thingsForStuff:CustomStuffTwo, @"Hello"]</code> would log</p>
  
  <blockquote>
    <p>"Two things: Hello and "</p>
  </blockquote>
  
  <p>...something that would be preferred to be caught before it happens.</p>
  
  <p>Is there a way to count the format specifiers in a string, preferably something lightweight/inexpensive?</p>