Is NSDocument's Saving Message Flow Threaded?

Scott Stevenson sstevenson at mac.com
Sat Feb 16 17:20:45 PST 2008


On Feb 16, 2008, at 2:54 PM, Jonathan Dann wrote:

> Could this be a threading issue with the way NSDocument saves  
> itself, even though I haven't put any threaded code in my app at  
> all? I ask this as the time interval between hitting command-W and  
> return seems to matter.
>
> Here's the relevant code from my NSDocument:
>
> - (IBAction)saveAllFiles:(id)sender;
> {
> 	....
> 	[self saveDocument:nil];
> }

One wild guess is that the "guts" of -saveDocument: actually happens  
in a delayed manner. Meaning it would get called after the end of the  
current user event. Some of the action methods tend to work this way.  
This seems to be reinforced by the error message you're getting.

If you can, you should try to just let NSDocument do the "unsaved  
documents" thing itself, since it has built-in functionality for that.  
If you need to do it yourself for some reason, you might have more  
luck with calling -writeToURL:ofType:error: on the document instead of  
-saveDocument:, though I'm not sure how the details of that would fit  
together.

     - Scott


More information about the MacOSX-dev mailing list