How did I break Auto Save during -[NSApp terminate:]?
How did I break Auto Save during -[NSApp terminate:]?
- Subject: How did I break Auto Save during -[NSApp terminate:]?
- From: Jerry Krinock <email@hidden>
- Date: Mon, 21 Oct 2013 13:38:48 -0700
After modifying a Core Data document-based OS X app, it no longer autosaves when quit. I need to fix that so it autosaves again.
Because my app is unfortunately complicated, I'm instead trying to understand how autosave works when quitting a normal app. Here is what I did:
• Get Apple Sample Code of Core Data, document-based app with Auto Save.
• Run the app.
• Modify a document.
• Activate breakpoint in -[NSManagedObjectContext save:].
• Quit the app.
As expected, breakpoint hit. Here is a piece of the call stack…
#13 0x00007fff8cc09d07 in __66-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_0 ()
#14 0x00007fff8cc048a9 in -[NSDocument continueFileAccessUsingBlock:] ()
#15 0x00007fff8cc091b4 in __block_global_18 ()
#16 0x00007fff8d07e662 in __block_global_44 ()
#17 0x00007fff866e9cd2 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#18 0x00007fff866aa47f in __CFRunLoopDoBlocks ()
#19 0x00007fff866ce7e4 in __CFRunLoopRun ()
#20 0x00007fff866ce0e2 in CFRunLoopRunSpecific ()
#21 0x00007fff84f0feb4 in RunCurrentEventLoopInMode ()
#22 0x00007fff84f0fb94 in ReceiveNextEventCommon ()
#23 0x00007fff84f0fae3 in BlockUntilNextEventMatchingListInMode ()
#24 0x00007fff8cd34533 in _DPSNextEvent ()
#25 0x00007fff8cd33df2 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#26 0x00007fff8cf5b461 in -[NSApplication _shouldTerminate] ()
#27 0x00007fff8cf5a737 in -[NSApplication terminate:] ()
Looking in particular at the bottom and top of that call stack, it appears that NSApplication somehow gets a reference to the open, modified document instance without consulting NSDocumentController. I'm surprised by that.
How/why could it do that?
Could NSDocumentController be hidden behind one of those "block" functions?
Can anyone explain how it might work?
In case anyone wants more information about the problem,
• In my app, +[NSDocument autosavesInPlace] *is* implemented and returns YES.
• There is another issue, beside the fact that saving does not occur: The app does not quit either. But neither does it hang. It does quit if I command it to quit a second time (with no changes).
• During that first failed quit, -[NSApp terminate:] returns without invoking -[NSDocumentController reviewUnsavedDocumentsWithAlertTitle:cancelable:delegate:didReviewAllSelector:] and without invoking the app delegate's applicationShouldTerminate:.
• During the second (successful except for saving) quit, the app delegate's applicationShouldTerminate: is invoked.
Thanks,
Jerry Krinock
_______________________________________________
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