Skip to content

Instantly share code, notes, and snippets.

@mayoff
Created September 18, 2012 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayoff/3744325 to your computer and use it in GitHub Desktop.
Save mayoff/3744325 to your computer and use it in GitHub Desktop.
Problems with NSHipster NSCharacterSet example
Errors in the squashing whitespace example code:
main.m:13:57: error: expected ';' at end of declaration
NSString *string = @"Lorem ipsum dolar sit amet ."
^
main.m:14:90: error: extraneous ']' before ';'
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
^
Actual result of the example code, on OS X 10.8.1 & Xcode 4.5 GM:
2012-09-18 12:04:32.843 tester[22688:c07] Lorem ipsum dolar sit amet .
Correct code:
NSString *string = @"Lorem ipsum dolar sit amet .";
string = [[[string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self != ''"]]
componentsJoinedByString:@" "];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment