Valid options for closeAllDocumentsWithDelegate

I am writing an application that should have several documents in one window (as suggested here . Therefore, I cannot just make it “document-based on the application”, but I'm still trying to use the document architecture to save individual files.

What I'm specifically trying to do is close all open documents and, preferably, save them if they have been changed. It seems that the best way to do this is to call the closeAllDocumentsWithDelegate method on the general document controller. But I do not know what parameters to pass. The docs say this:

func closeAllDocumentsWithDelegate (_ delegate: AnyObject ?, didCloseAllSelector madeCloseAllSelector: selector, contextInfo contextInfo: UnsafeMutablePointer)

They do not say what it means. Which delegate, selector, and contextual information should I call? I can not find examples of successful use of this method. I tried to see if I could escape with myself and zero to force it to compile:

SharedDocumentController.sharedDocumentController (). closeAllDocumentsWithDelegate (self, didCloseAllSelector: nil, contextInfo: nil)

But then I get the error message "Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x0)", which I am told that this is a null pointer exception . Thus, at least one of these basics is not-go, possibly due to a forced turn somewhere. OK, but what would I put there?

EDIT: as below, I add pic from stacktrace: stacktrace

And consoles:

2016-06-29 12:00:46.397 FourthDraftBrouillon[54275:6093667] An uncaught exception was raised
2016-06-29 12:00:46.397 FourthDraftBrouillon[54275:6093667] *** -[__NSArray0 objectAtIndex:]: index 2 beyond bounds for empty NSArray
2016-06-29 12:00:46.398 FourthDraftBrouillon[54275:6093667] (
    0   CoreFoundation                      0x00007fff981034f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff888b8f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff98123205 -[__NSArray0 objectAtIndex:] + 101
    3   libswiftCore.dylib                  0x0000000100075f4d _TFVs12_ArrayBuffer19_getElementSlowPathfSiPs9AnyObject_ + 125
    4   libswiftCore.dylib                  0x0000000100075370 _TFVs12_ArrayBuffer10getElementfTSi20wasNativeTypeCheckedSb_x + 144
    5   libswiftCore.dylib                  0x000000010008e60a _TFSag9subscriptFSix + 138
    6   FourthDraftBrouillon                0x0000000100007c6f _TFC20FourthDraftBrouillon14ViewController14collectionViewfTCSo16NSCollectionView35itemForRepresentedObjectAtIndexPathCSo11NSIndexPath_CSo20NSCollectionViewItem + 799
    7   FourthDraftBrouillon                0x0000000100007e2f _TToFC20FourthDraftBrouillon14ViewController14collectionViewfTCSo16NSCollectionView35itemForRepresentedObjectAtIndexPathCSo11NSIndexPath_CSo20NSCollectionViewItem + 79
    8   AppKit                              0x00007fff92bc40f6 -[_NSCollectionViewDataSourceAdapter collectionView:itemForRepresentedObjectAtIndexPath:] + 487
    9   UIFoundation                        0x00007fff95acd3ff -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 81
    10  UIFoundation                        0x00007fff95ace6f6 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 2167
    11  UIFoundation                        0x00007fff95ad0b24 -[_NSCollectionViewCore _layoutItems] + 208
    12  AppKit                              0x00007fff92bb76aa -[NSCollectionView layout] + 80
    13  AppKit                              0x00007fff923f14eb -[NSView _doLayout] + 53
    14  AppKit                              0x00007fff923f11a3 -[NSView _layoutSubtreeWithOldSize:] + 324
    15  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    16  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    17  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    18  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    19  AppKit                              0x00007fff923f06dc -[NSView layoutSubtreeIfNeeded] + 950
    20  AppKit                              0x00007fff92410025 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 82
    21  AppKit                              0x00007fff92482603 -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 244
    22  AppKit                              0x00007fff92b191f5 ___NSWindowGetDisplayCycleObserver_block_invoke6358 + 218
    23  AppKit                              0x00007fff924945fc __37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 719
    24  QuartzCore                          0x00007fff91702f71 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 85
    25  QuartzCore                          0x00007fff9170242c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 160
    26  QuartzCore                          0x00007fff917020ec _ZN2CA11Transaction6commitEv + 508
    27  AppKit                              0x00007fff925d9650 -[_NSScrollingConcurrentMainThreadSynchronizer _synchronize:completionHandler:] + 391
    28  AppKit                              0x00007fff925d9496 __80-[_NSScrollingConcurrentMainThreadSynchronizer initWithSharedData:constantData:]_block_invoke + 144
    29  libdispatch.dylib                   0x00000001005cbcc5 _dispatch_client_callout + 8
    30  libdispatch.dylib                   0x00000001005deba6 _dispatch_source_latch_and_call + 3387
    31  libdispatch.dylib                   0x00000001005d0cd8 _dispatch_source_invoke + 978
    32  libdispatch.dylib                   0x00000001005e3012 _dispatch_main_queue_callback_4CF + 1153
    33  CoreFoundation                      0x00007fff980b89e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    34  CoreFoundation                      0x00007fff980778dd __CFRunLoopRun + 1949
    35  CoreFoundation                      0x00007fff98076ed8 CFRunLoopRunSpecific + 296
    36  HIToolbox                           0x00007fff89e0b935 RunCurrentEventLoopInMode + 235
    37  HIToolbox                           0x00007fff89e0b76f ReceiveNextEventCommon + 432
    38  HIToolbox                           0x00007fff89e0b5af _BlockUntilNextEventMatchingListInModeWithFilter + 71
    39  AppKit                              0x00007fff9233cefa _DPSNextEvent + 1067
    40  AppKit                              0x00007fff9233c32a -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    41  AppKit                              0x00007fff92330e84 -[NSApplication run] + 682
    42  AppKit                              0x00007fff922fa46c NSApplicationMain + 1176
    43  FourthDraftBrouillon                0x0000000100008d04 main + 84
    44  libdyld.dylib                       0x00007fff930135ad start + 1
    45  ???                                 0x0000000000000003 0x0 + 3
)
2016-06-29 12:00:46.399 FourthDraftBrouillon[54275:6093667] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 2 beyond bounds for empty NSArray'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff981034f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff888b8f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff98123205 -[__NSArray0 objectAtIndex:] + 101
    3   libswiftCore.dylib                  0x0000000100075f4d _TFVs12_ArrayBuffer19_getElementSlowPathfSiPs9AnyObject_ + 125
    4   libswiftCore.dylib                  0x0000000100075370 _TFVs12_ArrayBuffer10getElementfTSi20wasNativeTypeCheckedSb_x + 144
    5   libswiftCore.dylib                  0x000000010008e60a _TFSag9subscriptFSix + 138
    6   FourthDraftBrouillon                0x0000000100007c6f _TFC20FourthDraftBrouillon14ViewController14collectionViewfTCSo16NSCollectionView35itemForRepresentedObjectAtIndexPathCSo11NSIndexPath_CSo20NSCollectionViewItem + 799
    7   FourthDraftBrouillon                0x0000000100007e2f _TToFC20FourthDraftBrouillon14ViewController14collectionViewfTCSo16NSCollectionView35itemForRepresentedObjectAtIndexPathCSo11NSIndexPath_CSo20NSCollectionViewItem + 79
    8   AppKit                              0x00007fff92bc40f6 -[_NSCollectionViewDataSourceAdapter collectionView:itemForRepresentedObjectAtIndexPath:] + 487
    9   UIFoundation                        0x00007fff95acd3ff -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 81
    10  UIFoundation                        0x00007fff95ace6f6 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 2167
    11  UIFoundation                        0x00007fff95ad0b24 -[_NSCollectionViewCore _layoutItems] + 208
    12  AppKit                              0x00007fff92bb76aa -[NSCollectionView layout] + 80
    13  AppKit                              0x00007fff923f14eb -[NSView _doLayout] + 53
    14  AppKit                              0x00007fff923f11a3 -[NSView _layoutSubtreeWithOldSize:] + 324
    15  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    16  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    17  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    18  AppKit                              0x00007fff923f13ff -[NSView _layoutSubtreeWithOldSize:] + 928
    19  AppKit                              0x00007fff923f06dc -[NSView layoutSubtreeIfNeeded] + 950
    20  AppKit                              0x00007fff92410025 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 82
    21  AppKit                              0x00007fff92482603 -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 244
    22  AppKit                              0x00007fff92b191f5 ___NSWindowGetDisplayCycleObserver_block_invoke6358 + 218
    23  AppKit                              0x00007fff924945fc __37+[NSDisplayCycle currentDisplayCycle]_block_invoke + 719
    24  QuartzCore                          0x00007fff91702f71 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 85
    25  QuartzCore                          0x00007fff9170242c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 160
    26  QuartzCore                          0x00007fff917020ec _ZN2CA11Transaction6commitEv + 508
    27  AppKit                              0x00007fff925d9650 -[_NSScrollingConcurrentMainThreadSynchronizer _synchronize:completionHandler:] + 391
    28  AppKit                              0x00007fff925d9496 __80-[_NSScrollingConcurrentMainThreadSynchronizer initWithSharedData:constantData:]_block_invoke + 144
    29  libdispatch.dylib                   0x00000001005cbcc5 _dispatch_client_callout + 8
    30  libdispatch.dylib                   0x00000001005deba6 _dispatch_source_latch_and_call + 3387
    31  libdispatch.dylib                   0x00000001005d0cd8 _dispatch_source_invoke + 978
    32  libdispatch.dylib                   0x00000001005e3012 _dispatch_main_queue_callback_4CF + 1153
    33  CoreFoundation                      0x00007fff980b89e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    34  CoreFoundation                      0x00007fff980778dd __CFRunLoopRun + 1949
    35  CoreFoundation                      0x00007fff98076ed8 CFRunLoopRunSpecific + 296
    36  HIToolbox                           0x00007fff89e0b935 RunCurrentEventLoopInMode + 235
    37  HIToolbox                           0x00007fff89e0b76f ReceiveNextEventCommon + 432
    38  HIToolbox                           0x00007fff89e0b5af _BlockUntilNextEventMatchingListInModeWithFilter + 71
    39  AppKit                              0x00007fff9233cefa _DPSNextEvent + 1067
    40  AppKit                              0x00007fff9233c32a -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
    41  AppKit                              0x00007fff92330e84 -[NSApplication run] + 682
    42  AppKit                              0x00007fff922fa46c NSApplicationMain + 1176
    43  FourthDraftBrouillon                0x0000000100008d04 main + 84
    44  libdyld.dylib                       0x00007fff930135ad start + 1
    45  ???                                 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
0
source share
1 answer

This method simply executes -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:for all open windows. Look at his documentation. (Linked above.)

Short form: you can pass a delegate object that will be informed of the close request using a method that responds to the selector that you passed.

, , , , , delegate , selector. Swift (Swift: function) @objc.

contextInfo - . . " " , .. . . nil .

, nil delegate. NULL ( ) . . .

0

Source: https://habr.com/ru/post/1648969/


All Articles