¿Cómo puedo reemplazar el texto en UITextView con el soporte NSUndoManager?

Quiero poder reemplazar parte del texto en un UITextView programáticamente, así que escribí este método como una categoría UITextView:

- (void) replaceCharactersInRange:(NSRange)range withString:(NSString *)newText{

    self.scrollEnabled = NO;

    NSMutableString *textStorage = [self.text mutableCopy];
    [textStorage replaceCharactersInRange:range withString:newText];

    //replace text but undo manager is not working well
    [[self.undoManager prepareWithInvocationTarget:self] replaceCharactersInRange:NSMakeRange(range.location, newText.length) 
                                                                       withString:[textStorage substringWithRange:range]];
    NSLog(@"before replacing: canUndo:%d", [self.undoManager canUndo]); //prints YES
    self.text = textStorage; 
    NSLog(@"after replacing: canUndo:%d", [self.undoManager canUndo]); //prints NO
    if (![self.undoManager isUndoing])[self.undoManager setActionName:@"replace characters"];
    [textStorage release];

    //new range:
    range.location = range.location + newText.length;
    range.length = 0;
    self.selectedRange = range;

    self.scrollEnabled = YES;

}

Funciona pero NSUndoManager deja de funcionar (parece que se reinicia) justo después de hacerself.text=textStorage He encontrado una API privada:-insertText:(NSString *) eso puede hacer el trabajo, pero quién sabe si Apple va a aprobar mi aplicación si la uso. ¿Hay alguna forma de reemplazar el texto en UITextView con el soporte NSUndoManager? ¿O tal vez me estoy perdiendo algo aquí?

Respuestas a la pregunta(4)

Su respuesta a la pregunta