iosobjective-cuiimagensmutablearraynsundomanager

How to perform NSUndoManager on NSMutableArray which contains Images?(Objective - C)


I'm creating an iOS App in which user can add effects to images. After applying that effect I've one done button which saves the current effect and allows user to add next effect on already applied effect, so user can apply more effects on other effects. If user won't press Done button then he switches between effects but with "Done" button he can apply effect on effect(Hope you get it!). Now I've two extra buttons named Undo & Redo. I'm saving all applied effects in an array when user clicks on done button.

Now I want to undo applied effects when undo button is clicked. And visa versa redo operation when redo button is clicked.

I know for that purpose I've to use NSUndoManager but I don't know from where I should start means I don't know how to use NSUndoManager with Array which contains Images?


Solution

  • Well, I've done this by different way!! besides using NSUndoManager I've just used 2 Arrays and done code with them.

    - (IBAction)onUndoClicked:(id)sender {    
     if ([arrUndo lastObject] == nil) {
            NSLog(@"EMPTY");
        }
        else
        {
            [arrRedo addObject:[arrUndo lastObject]];
            NSLog(@"ArrAdd %@", [arrUndo description]);
    
            [arrUndo removeLastObject];
            for (UIImage *obj in arrUndo) {
                if ([arrUndo lastObject] == obj) {
    
                    _imgClicked.image =  obj;
                }
            }
        }}
    
    - (IBAction)onRedoClicked:(id)sender {
    
        if ([arrRedo lastObject] == nil) {
            NSLog(@"EMPTY");
        }
        else
        {
            [arrEffectImages addObject:[arrRedo lastObject]];
            for (UIImage *obj in arrRedo) {
                if ([arrRedo lastObject] == obj) {
                    _imgClicked.image =  obj;
                }
            }
        }}