Skip to content

Instantly share code, notes, and snippets.

@rustle
Created March 4, 2013 04:14
Show Gist options
  • Save rustle/5079872 to your computer and use it in GitHub Desktop.
Save rustle/5079872 to your computer and use it in GitHub Desktop.
Example of prefixing a list with a leading character. In this case, adding a • to the front of each line.
NSString *someText = ...;
NSMutableString *someLines = [NSMutableString new];
[someText enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
// Make sure the line isn't just whitespace
NSMutableString *mutableLine = [line mutableCopy];
CFStringTrimWhitespace((__bridge CFMutableStringRef)mutableLine);
if ([mutableLine length])
{
[someLines appendFormat:@" • %@\n", line];
}
}];
if ([someLines length])
{
[someLines deleteCharactersInRange:NSMakeRange([someLines length] - 1, 1)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment