Skip to content

Instantly share code, notes, and snippets.

@austinzheng
Last active August 29, 2015 14:07
Show Gist options
  • Save austinzheng/d694393296a5c932f994 to your computer and use it in GitHub Desktop.
Save austinzheng/d694393296a5c932f994 to your computer and use it in GitHub Desktop.
Hakawai transformer example
// Text transformer (palindrome)
[self.textView transformSelectedTextWithTransformer:^NSAttributedString *(NSAttributedString *input) {
NSString *rawInput = [input string];
NSMutableString *buffer = [NSMutableString string];
unichar stackC;
for (NSInteger i=[rawInput length] - 1; i>=0; i--) {
stackC = [rawInput characterAtIndex:i];
[buffer appendString:[NSString stringWithCharacters:&stackC length:1]];
}
NSDictionary *attrs = [input attributesAtIndex:0 effectiveRange:NULL];
return [[NSAttributedString alloc] initWithString:buffer attributes:attrs];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment