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 7730323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:11:50+00:00 2026-06-01T06:11:50+00:00

In my app, users are able to quickly switch back and forth between objects

  • 0

In my app, users are able to quickly switch back and forth between objects and edit the text on those objects.

While they press “undo,” I want to bring up the relevant object so they can see the undo they are performing.

The objects are instances of an NSManagedObject subclass, and I’m using the undo manager that comes with the managedObjectContext you get when you create a UIManagedDocument.

The undo & redo is functioning fine otherwise.

How can I tell which object is being ‘undone’ for a given undo operation?

  • 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-06-01T06:11:52+00:00Added an answer on June 1, 2026 at 6:11 am

    So I figured this out. The method I needed was:

    • (void)awakeFromSnapshotEvents:(NSSnapshotEventType)flags

    Which can be overridden in a subclass of NSManagedObject.

    This method gets called whenever an object is affected by an undo or a redo. I was previously under the impression it only got called when an undo inserts or deletes an object, but it gets called if an object is changed as well.

    What I do in this method is post a notification containing the objectID, then when I receive that notification, I go and find the object that corresponds with the objectID I received.

    So in my NSManagedObject subclass, my awakeFromSnapshotEvents looks like this:

    - (void)awakeFromSnapshotEvents:(NSSnapshotEventType)flags {
       NSManagedObjectID *thisID = self.objectID;
       NSDictionary *userInfo = [NSDictionary dictionaryWithObject:thisID forKey:@"noticeObjectID"];
       [[NSNotificationCenter defaultCenter] postNotificationName:@"awakeFromSnapshotNotification" object:self userInfo:userInfo];
    }
    

    And in the receiver’s viewWillAppear, I register for the notification:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didAwakeManagedObject:) name:@"awakeFromSnapshotNotification" object:nil];
    

    Finally, my receiver’s didAwakeManagedObject: method looks like this. There’s probably a better way to do this, but this works fine for me. I happen to be concerned about the index position of the object I need within an NSOrderedSet backed by Core Data, so I just iterate through the ordered set til I find the right one.

    - (void) didAwakeManagedObject:(NSNotification*)notice {
       for (int i=0; i<project.orderedSet.count; i++) {
          if ([notice.userInfo objectForKey:@"noticeObjectID"] == [[project.orderedSet objectAtIndex:i] objectID]) {
             NSLog(@"%d IS EQUAL", i);
             return;
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I want users to be able to associate a file(s) they
I'm building an Android App where users need to be able to edit their
In my app users need to be able to enter numeric values with decimal
In my Rails app I want users to be able to input video links
I have an app that normal users need to be able to run, but
I have an app where we want users to be able to send us
I want to be able to log users out of my app built in
In my app users will be able to change element's border style attributes like
In a universal binary iPhone/iPad app of mine, users are able to adjust preferences
I am building an iOS app which users will be able to enter the

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.