PDA

View Full Version : Autosaving NStextView




SRossi
May 31, 2009, 05:36 AM
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:

- (void)textDidChange:(NSNotification *)notification
{
[self setString:[textView textStorage]];

[self autosaveDocumentWithDelegate:textView didAutosaveSelector:@selector(dataOfType:textStorage:) contextInfo:nil];
}

Thanks

Stephen



kainjow
Jun 1, 2009, 11:45 PM
From a look at the docs, the delegate and selector parameters are for when the autosave is complete. So for example:
- (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.");
}

SRossi
Jun 2, 2009, 05:32 AM
Thanks man looking at your code I understand what I have to do now.

Thnaks

Stephen