Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
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
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.");
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.