I have a NSPersistentDocument based app which fails to save a new document when autosavesInPlace
is set to return YES
, return NO
and the problem disappears.
- I create a new document
- Make some changes
- Save it , thus running
NSSaveAsOperation
, the name of the document and the URL changes and all appears to be well but the next save will throw a very descriptive
NSPersistentStoreSaveError = 134030, // unclassified save error - something we depend on returned an error
This only happens when the document attempts to run a save after a NSSaveAsOperation
. Any other save type will work fine as in changes to existing doc. Interesting effect is that if i dont change name or location i dont get this issue either.
Im getting an exception backtrace of
frame #0: 0x00007fff988143c5 libobjc.A.dylib
objc_exception_throw frame #1: 0x00007fff94c5f5f9 CoreData
-[NSPersistentStore(_NSInternalMethods) _preflightCrossCheck] + 697 frame #2: 0x00007fff94c3198b CoreData-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 603 frame #3: 0x00007fff94c5aa98 CoreData
-[NSManagedObjectContext save:] + 456 frame #4: 0x00007fff91baa101 AppKit-[NSPersistentDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:] + 3743 frame #5: 0x0000000100002de7 ZZZZ
-[ZZZZDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:] + 135 at ZZZZDocument.m:209 frame #6: 0x00007fff91baabc7 AppKit-[NSPersistentDocument writeSafelyToURL:ofType:forSaveOperation:error:] + 611 frame #7: 0x0000000100002ea3 ZZZZ
-[ZZZZDocument writeSafelyToURL:ofType:forSaveOperation:error:] + 115 at ZZZZDocument.m:223
any ideas?
Its not possible for a un-wrappered core data file
In the event you attempt to trap
NSSaveAsOperation
and do a migrate on the persistent store for that enum the construction of the...-journal
file will fail to create as its outside the sandbox.So we need to wrapper the file in a bundle/folder which is non-trivial using the
NSPersistentDocument
framework.Heres waiting for
NSManagedDocument
(thats a wishing well API)