In Core Data Programming Guide ▸ Using Persistent Stores ▸ Store Metadata, I 
read:

"Note that setting the metadata for a store does not change the information on 
disk until the store is actually
saved."

And indeed that is true.  So I add my metadata, in my document-saving method, 
*before* invoking NSPersistentDocument's -saveDocument: or saveDocumentAs:, 
which does the actual saving.

However, although the metadata does not get written to the disk by 
+[NSPersistentStoreCoordinator 
setMetadata:forPersistentStoreOfType:URL:error:], apparently the file 
modification time gets changed, because after doing so, and then invoking 
-saveDocument:, the dreaded warning sheet "This document's file has been 
changed by another application since you opened or saved it" shows its wretched 
face.

So, I do this:

• Read and remember the file's modification date (NSFileManager)
• Set the desired metadata
• Set the file's modification date back to the remembered value (NSFileManager)
• Invoke -saveDocument:

Voila - no more stupid warning sheet.

Why does +[NSPersistentStoreCoordinator 
setMetadata:forPersistentStoreOfType:URL:error:] change the file modification 
time given that, per documentation, it does not modify the file?

Is there a better way to do this?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to