Created
September 18, 2012 17:05
-
-
Save mayoff/3744325 to your computer and use it in GitHub Desktop.
Problems with NSHipster NSCharacterSet example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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