Very different Document Saving in Lion, even without enabling asynchronous
Very different Document Saving in Lion, even without enabling asynchronous
- Subject: Very different Document Saving in Lion, even without enabling asynchronous
- From: Jerry Krinock <email@hidden>
- Date: Wed, 17 Aug 2011 15:18:13 -0700
Although it's not mentioned in the 10.7 AppKit Release Notes, the various methods involving document saving are invoked sequentially in 10.7, rather than nested as they have always been, even if you have *not* enabled the new asynchronous document saving feature.
In the following lines, >> logs entering a method and << logs exiting.
In Mac OS X 10.6, methods are run nested/stacked, and as documented [1]…
>> [super saveDocument:]
>> [super saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]
>> -[MyDocu saveToURL:ofType:forSaveOperation:error:]
>> -[MyDocu writeSafelyToURL:ofType:forSaveOperation:error:]
>> [super writeSafelyToURL:ofType:forSaveOperation:error:]
<< [super writeSafelyToURL:ofType:forSaveOperation:error:]
<< -[MyDocu writeSafelyToURL:ofType:forSaveOperation:error:]
<< -[MyDocu saveToURL:ofType:forSaveOperation:error:]
<< [super saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]
<< [super saveDocument:]
In Mac OS X 10.7, they run sequentially, like this
>> [super saveDocument:]
<< [super saveDocument:]
>> [super saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]
<< [super saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]
>> -[MyDocu saveToURL:ofType:forSaveOperation:completionHandler:]
<< -[MyDocu saveToURL:ofType:forSaveOperation:completionHandler:]
>> -[MyDocu writeSafelyToURL:ofType:forSaveOperation:error:]
>> [super writeSafelyToURL:ofType:forSaveOperation:error:]
<< [super writeSafelyToURL:ofType:forSaveOperation:error:]
<< -[MyDocu writeSafelyToURL:ofType:forSaveOperation:error:]
It does not matter whether or not you enable synchronous saving. That is, -canAsynchronouslyWriteToURL:ofType:forSaveOperation: can either not be implemented, return NO, or return YES. It appears from call stacks [2][3] that their invocations are piled into a dispatch_sync type of queue.
This means that if you had overridden, say, saveDocument:, and put some code after invoking super, in 10.6 it runs after the actual save, but in 10.7 it runs way before. Not even close.
[1] http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Articles/ObjectInteractions.html
[2] Call stack in 10.7 showing invocation of -saveToURL:::::contextInfo:
#0 0x00186caf in -[MyDocu saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:] at MyDocu.m:3665
#1 0x9712131c in __-[NSDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_8
#2 0x9711c868 in -[NSDocument continueActivityUsingBlock:]
#3 0x97120df0 in __-[NSDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_7
#4 0x97137b5c in -[NSDocument _checkForFileChangesThenSave:saveAs:orCancel:]
#5 0x97120c15 in __-[NSDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_6
#6 0x971208ef in __-[NSDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_2
#7 0x9712ccf5 in __-[NSDocument _commitEditingWithDelegate:didSomethingSelector:contextInfo:thenContinue:]_block_invoke_1
#8 0x9713146b in -[NSDocument _commitEditingThenContinue:]
#9 0x972b170f in __-[NSPersistentDocument _documentEditor:didCommit:withContext:]_block_invoke_1
#10 0x96aba830 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
#11 0x96a6dcb1 in __CFRunLoopDoBlocks
#12 0x96a98ea7 in __CFRunLoopRun
#13 0x96a981ec in CFRunLoopRunSpecific
#14 0x96a98098 in CFRunLoopRunInMode
#15 0x94d39487 in RunCurrentEventLoopInMode
#16 0x94d40dc3 in ReceiveNextEventCommon
#17 0x94d40c32 in BlockUntilNextEventMatchingListInMode
#18 0x96d518ec in _DPSNextEvent
#19 0x96d51159 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#20 0x96d4d4cb in -[NSApplication run]
#21 0x96fe0b54 in NSApplicationMain
#22 0x00001e15 in main at MainApp-Main.m:49
[3] Call stack in 10.7 showing invocation of -saveToURL:::completionHandler:
#0 0x0018725d in -[MyDocu saveToURL:ofType:forSaveOperation:completionHandler:] at MyDocu.m:3750
#1 0x97121fcb in __-[NSDocument saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]_block_invoke_2
#2 0x9711cae0 in __-[NSDocument saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]_block_invoke_5
#3 0x9712ccf5 in __-[NSDocument _commitEditingWithDelegate:didSomethingSelector:contextInfo:thenContinue:]_block_invoke_1
#4 0x9713146b in -[NSDocument _commitEditingThenContinue:]
#5 0x972b170f in __-[NSPersistentDocument _documentEditor:didCommit:withContext:]_block_invoke_1
#6 0x96aba830 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
#7 0x96a6dcb1 in __CFRunLoopDoBlocks
#8 0x96a98ea7 in __CFRunLoopRun
#9 0x96a981ec in CFRunLoopRunSpecific
#10 0x96a98098 in CFRunLoopRunInMode
#11 0x94d39487 in RunCurrentEventLoopInMode
#12 0x94d40cee in ReceiveNextEventCommon
#13 0x94d40c32 in BlockUntilNextEventMatchingListInMode
#14 0x96d518ec in _DPSNextEvent
#15 0x96d51159 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#16 0x96d4d4cb in -[NSApplication run]
#17 0x96fe0b54 in NSApplicationMain
#18 0x00001e15 in main at MainApp-Main.m:49
_______________________________________________
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