Frage

I have an application which I use a third party library for saving and loading data. Normally when using NSDocument, I have override the - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError method and return the proper data, but with this library I only have access to a save routine (which could also create multiple files, otherwise I would save to a temporary file and return the data of the temporary file).

I also tried the following:

- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *errorOrNil))completionHandler
{
   librarySaveFunction(url.path);
}

Which works, but the documents title stays as 'MyFile - Edited', and if I try to save again, I get an error that the document has been updated by another application (I was able to resolve this by setting my file modification date, but the file is still marked as Edited and it feels very hackish).

Does anyone have a better suggestion on a better way to override the saving routine?

War es hilfreich?

Lösung

NSDocument has a whole huge hierarchy of methods involved in reading and writing data. Which one you should override depends a lot on the specifics of your particular situation and how they relate to the default read/write machinery. My gut reaction when I saw this question was that you don't want to be overriding the -save* methods, you want to be overriding a -write* method (probably -writeToURL:ofType:forSaveOperation:originalContentsURL:error:), but it's really hard to say without knowing more about the specifics of your app (and this third party library you're using.)

The definitive discussion of the various override points and situations where they're suitable is here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top