What's a simple implementation of the following NSString
category method that returns the number of words in self
, 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 & readability at the sacrifice of a bit of performance.
@interface NSString (Additions)
- (NSUInteger)wordCount;
@end
I found the following solutions:
- implementation of -[NSString wordCount]
- implementation of -[NSString wordCount] - seems a bit simpler
But, isn't there a simpler way?