Re: Modifying the save path in an NSDocument based application
Re: Modifying the save path in an NSDocument based application
- Subject: Re: Modifying the save path in an NSDocument based application
- From: Steve Mills <email@hidden>
- Date: Tue, 17 Sep 2013 08:41:19 -0500
On Sep 17, 2013, at 07:49:56, Pax <email@hidden>
wrote:
> I have a slightly odd requirement in that I need to modify, under certain circumstances, the save path used for an NSDocument based application. The reason for this is that I may, depending on the format chosen by the user, need to unpack the data into multiple files. Under this circumstance, I want to create a folder at the location specified by the user, with the name of the source file (less the extension) as the folder name, and then I'll unpack the source file into this directory.
>
> I thought that this would be nice and simple - but it seems that the URL used when saving is an intermediate URL. My file doesn't get created at the final destination location (and, because it doesn't, I can't easily modify the path). What I planned to do is this:
>
> - (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)inTypeName error:(NSError **)outError
> When I check url I get something like file://localhost/private/var/folders/6w/6dmwl9c938g4m94jm7s_8ml80000gn/T/TemporaryItems/(A Document Being Saved By Extractor)/Christmas.ext
You might try overriding saveToURL:ofType:forSaveOperation:completionHandler: instead. writeToURL is at a very low level in the save operation, and if you look at the stack, I bet writeSafelyToURL:ofType:forSaveOperation:error: is one of the callers of writeToURL. What that does is first write the file to a temp file, then if all goes well, moves it to the actual location, replacing the original file if it exists. So you'll want to let that happen. But up in saveToURL you should be able to point it to your new dir at a higher level, before writeSafelyToURL does its thing.
--
Steve Mills
office: 952-818-3871
home: 952-401-6255
cell: 612-803-6157
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden