title: Objective-C: -[NSString wordCount]
body: <p>What's a simple implementation of the following <code>NSString</code> category method that returns the number of words in <code>self</code>, where words are separated by any number of consecutive spaces or newline characters? Also, the string will be less than 140 characters, so in this case, I prefer simplicity &amp; readability at the sacrifice of a bit of performance.</p>
  
  <pre><code>@interface NSString (Additions)
  - (NSUInteger)wordCount;
  @end
  </code></pre>
  
  <p>I found the following solutions:</p>
  
  <ul>
  <li><a href="http://macdevnotes.com/nsstring-word-count" rel="noreferrer">implementation of -[NSString wordCount]</a></li>
  <li><a href="http://borkware.com/quickies/one?topic=NSString" rel="noreferrer">implementation of -[NSString wordCount]</a> - seems a bit simpler</li>
  </ul>
  
  <p>But, isn't there a simpler way?</p>