1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Autosaving NStextView

Discussion in 'Mac Programming' started by SRossi, May 31, 2009.

  1. macrumors regular

    #1
    Hi all, I am trying to implement autosaving to my NSTextView everytime that a user enters a character i have set up a textDidChange method but I do not know about autosaving. I have looked on the Apple documentation but there is very little on autosaving this is the code I have:

    Code:
    - (void)textDidChange:(NSNotification *)notification
    {
    	[self setString:[textView textStorage]];
    	
    	[self autosaveDocumentWithDelegate:textView didAutosaveSelector:@selector(dataOfType:textStorage:) contextInfo:nil];
    }
    Thanks

    Stephen
     
  2. Moderator emeritus

    kainjow

    #2
    From a look at the docs, the delegate and selector parameters are for when the autosave is complete. So for example:
    Code:
    - (void)textDidChange:(NSNotification *)notification
    {
        [self setString:[textView textStorage]];
        [self autosaveDocumentWithDelegate:self
            didAutosaveSelector:@selector(document:didAutosave:contextInfo:)
            contextInfo:NULL];
    }
    
    - (void)document:(NSDocument *)document
            didAutosave:(BOOL)didAutosaveSuccessfully
            contextInfo:(void *)contextInfo
    {
        NSLog(@"Autosave complete.");
    }
     
  3. macrumors regular

    #3
    Thanks man looking at your code I understand what I have to do now.

    Thnaks

    Stephen
     

Share This Page