Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 6
    That definition would conlude that the string " /r/n /r/n" is empty, when it clearly is not - it contains whitespace. Your function is really: -(BOOL)isWhitespace(NSString*); Commented Mar 28, 2010 at 20:52
  • 6
    A corollary to this. I implemented this category, and there is a twist. If you call this on a nil string, this function is never called, and you get back a NO(or what evaluates to NO) as a return value. Then you think it's not empty...This might work if the name was isFilled or something like that. Commented Oct 29, 2010 at 13:53
  • I guess the right category would then be: @implementation NSString (Empty) - (BOOL) empty{ return ([[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]length] == 0); } @end As a combination of Marc's and Kyle's answer. Commented Sep 25, 2013 at 12:00