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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:57:17+00:00 2026-05-27T03:57:17+00:00

Continuously updates value binding option triggers continuous autosaveInPlace attempts (for every single char you

  • 0

Continuously updates value binding option triggers continuous autosaveInPlace attempts (for every single char you type).

Hello everyone, this is my first question here!

I hope I will ask it correctly… 🙂

I’m trying to add Lion’s autosave mechanism to my core data document-based application.
In my NSPersistentDocument subclass I’m overriding the +(BOOL)autosaveInPlace method returning YES and all the features work correctly (saving, new menus, the version browser…).

My problem is that when I’m typing in text fields bound to my model with the continuously updates value option, the autosave system triggers a save operation upon every single keystroke! The spinning beach-ball does not appear (maybe because my documents are fairly small) but the typing is really really slow.

AutosaveInPlace is called for every key press, and subsequently the saveToURL… and writeToURL… methods.

I found nearly nothing on the subject on the net, and even lesser in the official documentation from Apple.

In the Autosave and Versions WWDC ’11 video the engineer provides an incomplete example of how to cancel an autosave, when [self autosavingIsImplicitlyCancellable] returns YES, but in my case, this method returns always NO. This must be the expected behavior: the value must be continuously updated and as the on-disk file must at all times be identical to the contents the user sees on screen, this save must not be cancelled.

I found a more useful example on the net of how to prevent the save from being initiated in the first place (ovverriding the save… method instead of the write… one).

 -(void)saveToURL:(NSURL *)url
           ofType:(NSString *)typeName
 forSaveOperation:(NSSaveOperationType)saveOperation
completionHandler:(void (^)(NSError *errorOrNil))completionHandler {
    if (saveOperation == NSAutosaveInPlaceOperation) {
        if ([self isWritingInMyTextField]) {
            completionHandler([NSError errorWithDomain:NSCocoaErrorDomain
                                                  code:NSUserCancelledError
                                              userInfo:nil]);
            return;
            }
        }
    [super saveToURL:url ofType:typeName forSaveOperation:saveOperation completionHandler:completionHandler];
}

This is working. In case of an autosave, if my textfield has the focus, I pass the documented silent cocoa error to the completion handler and the save doesn’t occur, the UI is responsive as before. The original poster claims that in this way the autosave is actually delayed until the current activity ends, but I’m not sure about that.

My problem is that I don’t want to have to observe every single text field for begin/end editing and have to manually trigger an autosave myself every now and then because I’m preventing the system to do it while I’m writing in text fields. The system should just understand it’s not reasonable to trigger a save on a single keystroke basis.

In the WWDC ’11 video, the engineer points to a way of checking for the user activity through NSRunLoop and events but it’s far beyond my understanding. I searched the documentation for NSRunLoop, NSEvent but I can’t figure out how to get the info «the user’s actively typing something!».

If anybody could point me in the right direction on this topic, I’d be grateful.

It would be better if someone knew the recommended way of dealing with this issue!

As a final consideration, I can read in the documentation for NSPersistentDocument that «NSPersistentDocument does not support NSDocument’s asynchronous saving API as that API requires accessing the document’s state on multiple threads and that violates NSManagedObjectContext’s requirements.». Does this mean that unless your app’s documents are very small you shouldn’t use autosave at all?
Well, Apple seems to want autosave to become the new way of doing things for all new apps, so I can’t figure out how it could happen if developers must renounce to core data.

  • 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-27T03:57:17+00:00Added an answer on May 27, 2026 at 3:57 am

    Here’s my working answer.

    +(BOOL)autosavesInPlace { return YES; }
    
    -(BOOL)isUserTyping {
    
        NSUInteger eventType = [[NSApp currentEvent] type];
        return (eventType == NSKeyDown ||
                eventType == NSKeyUp ||
                eventType == NSFlagsChanged);
    }
    
    -(void)saveToURL:(NSURL *)url
              ofType:(NSString *)typeName
    forSaveOperation:(NSSaveOperationType)saveOperation
    completionHandler:(void (^)(NSError *errorOrNil))completionHandler {
    
        if (saveOperation == NSAutosaveInPlaceOperation) {
    
            if ([self isUserTyping]) {
    
                completionHandler([NSError errorWithDomain:NSCocoaErrorDomain
                                                      code:NSUserCancelledError
                                                  userInfo:nil]);
    
                return;
            }
        }
    
        [super saveToURL:url ofType:typeName forSaveOperation:saveOperation completionHandler:completionHandler];
    }
    

    I don’t know if my isUserTyping method is the greatest way of doing it. The WWDC ’11 video engineer’s use of the run loop to check for user activity remains a mystery for me!

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

Sidebar

Related Questions

In Xcode 3 Interface Builder, when I check Continuously Updates Value in NSTextView attributedString
i am doing a continuously select every 10seconds, so i thought i would do
The situation is like this: there is a continuous loop, that updates some values.
with this type of XML format? <details> <detail> <name>Woofer Size</name> <value>12</value> </detail> <detail> <name>Woofer
1) <h:column> <h:selectBooleanCheckbox value=#{CertificateInsuranceAddRq.insuranceSvcRq.com_csc_CertificateInsuranceAddRq.com_csc_CertificateInfo.com_csc_RenewalInd}> <p:ajax event=change update=continuous /> </h:selectBooleanCheckbox> <h:outputLabel value=#{label.renewable} style=font-weight:bold /> </h:column>
I have an app that starts a service that continuously updates the notification bar.
I continuously find places where I need to use the <br /> tag because
I want to continuously sample from my PC's audio line in using C# (then
I have a strange phenomenon while continuously instantiating a com-wrapper and then letting the
I have a command line app the continuously outputs YAML data in the form:

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.