0

I am trying to develop an iPhone application (demo project) using objective-C which can apply multiple photographic effects to images.

The application is up and running but I thought of implementing an 'undo' and 'redo' function in the UI. I have successfully coded one-level of undo-redo, i.e one step backward or forward with ease. But the concept gets complicated when incorporating multiple levels of undo and redo action. It gets especially murky when user undoes a sequence of steps and then branches into doing something else. The more states I try to save, the more deluded I become.

I would like to know if there is a standard best practice for implementing this sort of action. Any architecture or framework that I should be using? What is the generally accepted procedure for doing this? Any general advice for streamlining this method would be appreciated.

Please help.

metsburg
  • 2,021
  • 1
  • 20
  • 32
  • 1
    Try implementing archive and unarchived concept in your app... – Vinay Bagale Feb 22 '13 at 05:22
  • How complicated and memory intensive is your app? You could just implement a stack, and use the push/pop paradigm to move forward and backward. – Bergasms Feb 22 '13 at 05:25
  • Are you suggesting archive string representing the effects being applied OR archive the images as objects themselves? I thought about it... but felt like the first method may be a little difficult to decode and manage AND the second method would spell disaster for the memory. However, I can't be very sure without trying this out. Nevertheless, thanks for the suggestion. – metsburg Feb 22 '13 at 05:32
  • @ Bergasms : Fairly memory intensive. Stack is definitely nice and simple, but I was wondering what happens when user goes back a few steps and creates a new branch. Don't you think a tree structure would be more suitable to the purpose? Moreover, as I push/pop effects from the stack ... do I keep applying effects to the displayed view on real time? It is fairly complicated to go back to the previous effect. So, every time user goes back a step, I'd have to start from the root node and traverse down the entire stack to reach at the (n-1)th step. What are your thoughts on this? – metsburg Feb 22 '13 at 05:41
  • @user2041826 You can just keep a track of your actions in a stack, not a tree, since tree will increase your complexity. – DivineDesert Feb 22 '13 at 05:46
  • Yes, agreed. Tree will be complex in terms of time. :( – metsburg Feb 22 '13 at 05:50
  • Not only in terms of time, in terms of managing your stack and keeping your track – DivineDesert Feb 22 '13 at 05:51

1 Answers1

1

It all depends on how you process your image.

If you are playing with images you can use NSUndoManager, where you can keep track of image processing.

Else you can keep track of array of actions that are performed on your image, this is less preferred.

But all depends on your requirements and how you process your image,

Important thing to be taken care of is your memory in such types of actions.

If you want to reuse your actions when you next load your app you can use NSKeyArchiever.

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
  • No, I don't want to reuse my actions on next load. NSUndoManager sounds like a nice option. I'll start exploring this.... but I must say once a series of effects has been applied to an image, there is no other function that can take down the effects step by step. So, from what I understand, I have to manage a buffer view for every step I apply, right? Correct me if I am wrong... but that might put fair amount of stress on memory. – metsburg Feb 22 '13 at 05:46
  • Are you applying new effects on modified image / using original image for each action ? – DivineDesert Feb 22 '13 at 05:48
  • @CrazyCreator: Yes, the effects stack up on one another. Original image is used on the first step. – metsburg Feb 22 '13 at 05:52
  • @user2041826 Then you can save image in archieve and serialise it, This is best practice I ever found, when user undo an action, just load the image and update your archieve. Hope this works – DivineDesert Feb 22 '13 at 05:55
  • that sounds like a decent concept. this concept of archiving is new to me. can you please share a link where I can find out more about this? specially when applied to undo-redo. – metsburg Feb 22 '13 at 06:03
  • https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Articles/archives.html#//apple_ref/doc/uid/20000946-BAJDBJAI – DivineDesert Feb 22 '13 at 06:10
  • Welcome, hope it helps you – DivineDesert Feb 22 '13 at 06:11