Skip to content

Instantly share code, notes, and snippets.

@scheinem
Created July 3, 2013 21:15
Show Gist options
  • Save scheinem/5922890 to your computer and use it in GitHub Desktop.
Save scheinem/5922890 to your computer and use it in GitHub Desktop.
/**
* Detects paragraphs in an UITextView and stores it in an NSMutableArray called "paragraphs"
*
* Author: Manfred Scheiner (@scheinem)
* Created on 03.07.2013
*/
- (void)textViewDidChange:(UITextView *)textView; {
NSMutableArray *paragraphs = [NSMutableArray array];
for (NSString *component in [textView.text componentsSeparatedByString:@"\n"]) {
NSMutableString *mutableComponent = [component mutableCopy];
while ([mutableComponent rangeOfString:@"\n"].location != NSNotFound) {
[mutableComponent deleteCharactersInRange:[mutableComponent rangeOfString:@"\n"]];
}
if (mutableComponent.length > 0) {
[paragraphs addObject:mutableComponent];
}
}
NSLog(@"Number of paragraphs: %u", paragraphs.count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment