Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:34:13+00:00 2026-05-28T16:34:13+00:00

I have a somewhat complex data model in my iPad application (an OpenGL drawing

  • 0

I have a somewhat complex data model in my iPad application (an OpenGL drawing app), and I’m working on implementing undo/redo functionality. I like the fact that Core Data will undo data model changes for free, but I don’t know if the built-in functionality will be sufficient for me.

I have seen lots of examples of undo/redo being implemented in drawing apps, however they generally do the following:

  1. Tell the managed object context to undo.
  2. Redraw everything on the page from the changed data model.

This is horribly inefficient – in my app I need to be able to perform an action to undo based on the particular object that is being ‘undone’, and often this means refreshing only part of the canvas.

So my question is this: can I register my own undo operations and use that in conjunction with the built-in undos? For example, say I do the following when the user draws a line:

- (void)drawLineFromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint
{
    // Register the undo operation.
    [[[managedObjectContext undoManager] prepareWithInvocationTarget:self] 
                                               removeObjectWithIndex:nextObjectIndex];

    // Draw the line object.  
    [self drawLineObjectWithIndex:nextObjectIndex fromPoint:startPoint toPoint:endPoint];

    // Save the new object to the data model.
    [MyCoreDataHelper saveLineObjectWithIndex:nextObjectIndex fromPoint:startPoint toPoint:endPoint];

    nextObjectIndex++;
}

When I come to undo this action, will the invocation be fired and the model changed appropriately? Or does this situation require that I abandon the built-in managed object context undo system and roll my own using just the NSUndoManager, including deleting and editing the data model myself? Unless I can tell what the built-in undo/redo is actually undoing, it looks like this could get horribly messy and complicated…

Edit: I suspect (if the idea above was to work) I would need to wrap it into an undo group, so that my registered undo operation would be grouped with the data model changes?

Another Edit: Also, can I guarantee the order in which undo actions will be carried out? In other words, if I call undo after the core data changes are saved and my undo action is registered, can I be sure that a deleted entity will be reinstated before my undo action is called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:34:14+00:00Added an answer on May 28, 2026 at 4:34 pm

    Do you know then if it is possible to identify what data was changed from the undo?

    Why don’t you check out the notifications for NSManagedObjectContext (Apple Docs)

    Specifically look at the notification’s userInfo with the keys NSInsertedObjectsKey, NSUpdatedObjectsKey, and NSDeletedObjectsKey.

    Also, can I guarantee the order in which undo actions will be carried out?

    Well, undo works via stack (last in, first out), so you “should” be able to trace your steps. Obviously you have to be very specific in the order you register your undos if you want things to unfold correctly. A few lines of code that help me trace the undo stack just to see what is behind the veil of mystery:

    id undoStack, redoStack;
    object_getInstanceVariable(undoManager, "_undoStack", &undoStack);
    object_getInstanceVariable(undoManager, "_redoStack", &redoStack);
    NSLog(@"%@", [undoStack description]);
    NSLog(@"%@", [redoStack description]);
    

    (Props to this site for the above code)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP web app that generates a somewhat complex report from our
I have a somewhat complex pricing mechanism in my application- Here are some of
Currently I have a service that downloads about 500 records of somewhat complex data,
I'm working on a fairly complex Android application that requires a somewhat large amount
I have a Java main application with somewhat complex command line arguments. These arguments
I have a somewhat-long-running stored procedure being called from a PB application. I want
I have an ObservableCollection of ChildViewModels with somewhat complex behaviour. When I go to
I have a somewhat complex custom user control, created in C# .NET, which is
I have a somewhat complex query with multiple (nested) sub-queries, which I want to
I have a somewhat complex regular expression which I'm trying to match against a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.