Using Cocoa NSSavePanel in Sandbox causes Assertion failure - swift

I'm trying to use the NSSavePanel and added this line to my code.
let test = NSSavePanel()
Everytime this code is called the this error appears.
I'm not quite sure what is happening here because I'm only creating a new object.
Any help appreciated.
Thanks!
*** Assertion failure in -[NSVBSavePanel viewWillInvalidate:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.20.106/Nav.subproj/OpenAndSavePanelRemote/NSVBOpenAndSavePanels.m:387
2017-12-23 18:11:33.110099+0100 test[27753:1527254] -[NSVBSavePanel init] caught non-fatal NSInternalInconsistencyException 'bridge absent' with backtrace (
0 CoreFoundation 0x00007fff3ca1900b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff635f7c76 objc_exception_throw + 48
2 CoreFoundation 0x00007fff3ca1eda2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fff3eb2b260 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 AppKit 0x00007fff3a1e748e -[NSVBSavePanel viewWillInvalidate:] + 188
5 ViewBridge 0x00007fff60f376f2 -[NSRemoteView invalidate:] + 292
6 ViewBridge 0x00007fff60f44e88 -[NSRemoteView _advanceToConfigPhaseLegacy] + 1111
7 ViewBridge 0x00007fff60f45d1b -[NSRemoteView _viewServiceMarshalProxy:withDetailedErrorHandler:] + 230
8 ViewBridge 0x00007fff60f46104 -[NSRemoteView _viewServiceMarshalProxy:withErrorHandler:] + 78
9 ViewBridge 0x00007fff60f38194 -[NSRemoteView bridge] + 227
10 AppKit 0x00007fff3a1a2e36 -[NSVBSavePanel init] + 292
11 AppKit 0x00007fff3a66fc7e -[NSSavePanel initWithContentRect:styleMask:backing:defer:] + 71
12 AppKit 0x00007fff3a1a3093 -[NSPanel init] + 87
13 test 0x0000000100002933 _T0So11NSSavePanelCABycfcTO + 19
14 test 0x000000010000131c _T0So11NSSavePanelCABycfC + 60
15 test 0x0000000100001285 _T04test14ViewControllerC11viewDidLoadyyF + 85
16 test 0x00000001000013b4 _T04test14ViewControllerC11viewDidLoadyyFTo + 36
17 AppKit 0x00007fff39fc1632 -[NSViewController _sendViewDidLoad] + 97
18 AppKit 0x00007fff39fb806d -[NSViewController _loadViewIfRequired] + 390
19 AppKit 0x00007fff39fb7e9d -[NSViewController view] + 30
20 AppKit 0x00007fff3a13675d -[NSWindow _contentViewControllerChanged] + 109
21 Foundation 0x00007fff3ea99ade -[NSObject(NSKeyValueCoding) setValue:forKey:] + 331
22 AppKit 0x00007fff3a1794b1 -[NSWindow setValue:forKey:] + 111
23 AppKit 0x00007fff3a179415 -[NSIBUserDefinedRuntimeAttributesConnector establishConnection] + 637
24 AppKit 0x00007fff39f45bbd -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1430
25 AppKit 0x00007fff3a04113a -[NSNib _instantiateNibWithExternalNameTable:options:] + 679
26 AppKit 0x00007fff3a040d96 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136
27 AppKit 0x00007fff3a797180 -[NSStoryboard instantiateControllerWithIdentifier:] + 236
28 AppKit 0x00007fff39f39ecf NSApplicationMain + 729
29 test 0x0000000100002d0d main + 13
30 libdyld.dylib 0x00007fff641e7115 start + 1
)

Your File Access permissions for the User Selected File type are probably still set to the default Read Only value
Navigate to the 'Capabilities' tab for your target
Set the User Selected File permission to Read/Write
Run your app (the bridge absent error should be gone)

Related

macCatalyst crash on UIScene in macOS 11 (Big Sur) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a macCatalyst app that works perfectly on macOS 10.14, however on upgrading to macOS 11 (Big Sur) both I and my users are complaining that the app crashes on launch. I get an error message "Parameter was not of class UIScene" - do macCatalyst apps now require the use of scenes?
On further inspection, I see the following:
2020-11-28 01:48:40.327810+0000 AppName [13691:435322] *** Assertion failure in -[_UISceneMacHelperUtilities sceneIdentifierForUIScene:], _UISceneMacHelperUtilities.m:83
2020-11-28 01:48:40.336334+0000 AppName[13691:435322] [General] An uncaught exception was raised
2020-11-28 01:48:40.336423+0000 AppName[13691:435322] [General] Parameter was not of class UIScene.
2020-11-28 01:48:40.336545+0000 AppName[13691:435322] [General] (
0 CoreFoundation 0x00007fff204ae6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff201e63c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff204d7512 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff212906c9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff44a7b2c6 -[_UISceneMacHelperUtilities sceneIdentifierForUIScene:] + 195
5 UIKitMacHelper 0x00007fff34045f74 __46-[UINSApplicationDelegate _setupKeyWindowSync]_block_invoke + 393
6 Foundation 0x00007fff21192d6b -[__NSObserver _doit:] + 287
7 CoreFoundation 0x00007fff20429fdc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
8 CoreFoundation 0x00007fff204c589b ___CFXRegistrationPost_block_invoke + 49
9 CoreFoundation 0x00007fff204c580f _CFXRegistrationPost + 454
10 CoreFoundation 0x00007fff203fabce _CFXNotificationPost + 723
11 Foundation 0x00007fff21166abe -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
12 UIKitCore 0x00007fff44376779 -[UIWindow _makeKeyWindowIgnoringOldKeyWindow:] + 567
13 AppName 0x00000001013fe0c0 $s25AppName13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0K7SessionCSo0K17ConnectionOptionsCtF + 1520
14 AppName 0x00000001013feaa6 $s25AppName13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0K7SessionCSo0K17ConnectionOptionsCtFTo + 118
15 UIKitCore 0x00007fff44221a31 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1463
16 UIKitCore 0x00007fff4421ffb1 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1109
17 UIKitCore 0x00007fff4421ecfe -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 299
18 UIKitCore 0x00007fff4421eb49 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 358
19 FrontBoardServices 0x00007fff317e7312 -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 391
20 FrontBoardServices 0x00007fff318045df __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.176 + 102
21 FrontBoardServices 0x00007fff317d60c1 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
22 FrontBoardServices 0x00007fff318042b7 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 354
23 libdispatch.dylib 0x00000001040c50b0 _dispatch_client_callout + 8
24 libdispatch.dylib 0x00000001040c8927 _dispatch_block_invoke_direct + 286
25 FrontBoardServices 0x00007fff317d5fd8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
26 FrontBoardServices 0x00007fff3181e1c3 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 433
27 FrontBoardServices 0x00007fff317d5fa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 22
28 CoreFoundation 0x00007fff204349fc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x00007fff20434964 __CFRunLoopDoSource0 + 180
30 CoreFoundation 0x00007fff204346df __CFRunLoopDoSources0 + 248
31 CoreFoundation 0x00007fff20433111 __CFRunLoopRun + 890
32 CoreFoundation 0x00007fff204326be CFRunLoopRunSpecific + 563
33 HIToolbox 0x00007fff2869efd0 RunCurrentEventLoopInMode + 292
34 HIToolbox 0x00007fff2869edcc ReceiveNextEventCommon + 709
35 HIToolbox 0x00007fff2869eaef _BlockUntilNextEventMatchingListInModeWithFilter + 64
36 AppKit 0x00007fff22c4bf85 _DPSNextEvent + 883
37 AppKit 0x00007fff22c4a74b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1366
38 AppKit 0x00007fff22c3cbda -[NSApplication run] + 586
39 AppKit 0x00007fff22c10f31 NSApplicationMain + 816
40 AppKit 0x00007fff22f0744d _NSApplicationMainWithInfoDictionary + 16
41 UIKitMacHelper 0x00007fff3403332e UINSApplicationMain + 1418
42 UIKitCore 0x00007fff44202e30 UIApplicationMain + 144
43 AppName 0x00000001014da40b main + 75
44 libdyld.dylib 0x00007fff20357631 start + 1
)
2020-11-28 01:48:40.337802+0000 AppName[13691:435322] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameter was not of class UIScene.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff204ae6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff201e63c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff204d7512 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff212906c9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff44a7b2c6 -[_UISceneMacHelperUtilities sceneIdentifierForUIScene:] + 195
5 UIKitMacHelper 0x00007fff34045f74 __46-[UINSApplicationDelegate _setupKeyWindowSync]_block_invoke + 393
6 Foundation 0x00007fff21192d6b -[__NSObserver _doit:] + 287
7 CoreFoundation 0x00007fff20429fdc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
8 CoreFoundation 0x00007fff204c589b ___CFXRegistrationPost_block_invoke + 49
9 CoreFoundation 0x00007fff204c580f _CFXRegistrationPost + 454
10 CoreFoundation 0x00007fff203fabce _CFXNotificationPost + 723
11 Foundation 0x00007fff21166abe -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
12 UIKitCore 0x00007fff44376779 -[UIWindow _makeKeyWindowIgnoringOldKeyWindow:] + 567
13 AppName 0x00000001013fe0c0 $s25AppName13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0K7SessionCSo0K17ConnectionOptionsCtF + 1520
14 AppName 0x00000001013feaa6 $s25AppName13SceneDelegateC5scene_13willConnectTo7optionsySo7UISceneC_So0K7SessionCSo0K17ConnectionOptionsCtFTo + 118
15 UIKitCore 0x00007fff44221a31 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1463
16 UIKitCore 0x00007fff4421ffb1 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1109
17 UIKitCore 0x00007fff4421ecfe -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 299
18 UIKitCore 0x00007fff4421eb49 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 358
19 FrontBoardServices 0x00007fff317e7312 -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 391
20 FrontBoardServices 0x00007fff318045df __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.176 + 102
21 FrontBoardServices 0x00007fff317d60c1 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
22 FrontBoardServices 0x00007fff318042b7 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 354
23 libdispatch.dylib 0x00000001040c50b0 _dispatch_client_callout + 8
24 libdispatch.dylib 0x00000001040c8927 _dispatch_block_invoke_direct + 286
25 FrontBoardServices 0x00007fff317d5fd8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
26 FrontBoardServices 0x00007fff3181e1c3 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 433
27 FrontBoardServices 0x00007fff317d5fa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 22
28 CoreFoundation 0x00007fff204349fc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x00007fff20434964 __CFRunLoopDoSource0 + 180
30 CoreFoundation 0x00007fff204346df __CFRunLoopDoSources0 + 248
31 CoreFoundation 0x00007fff20433111 __CFRunLoopRun + 890
32 CoreFoundation 0x00007fff204326be CFRunLoopRunSpecific + 563
33 HIToolbox 0x00007fff2869efd0 RunCurrentEventLoopInMode + 292
34 HIToolbox 0x00007fff2869edcc ReceiveNextEventCommon + 709
35 HIToolbox 0x00007fff2869eaef _BlockUntilNextEventMatchingListInModeWithFilter + 64
36 AppKit 0x00007fff22c4bf85 _DPSNextEvent + 883
37 AppKit 0x00007fff22c4a74b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1366
38 AppKit 0x00007fff22c3cbda -[NSApplication run] + 586
39 AppKit 0x00007fff22c10f31 NSApplicationMain + 816
40 AppKit 0x00007fff22f0744d _NSApplicationMainWithInfoDictionary + 16
41 UIKitMacHelper 0x00007fff3403332e UINSApplicationMain + 1418
42 UIKitCore 0x00007fff44202e30 UIApplicationMain + 144
43 AppName 0x00000001014da40b main + 75
44 libdyld.dylib 0x00007fff20357631 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameter was not of class UIScene.'
terminating with uncaught exception of type NSException

Allow user customization of Touch Bar in macCatalyst

In a catalyst Swift project a UIViewController subclass creates a TouchBar like this:
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.defaultItemIdentifiers = [<<some>>]
touchBar.customizationAllowedItemIdentifiers = [<<more>>]
touchBar.customizationIdentifier = "com.me.myapp.touchbar"
return touchBar
}
The default items show up on the TouchBar, but there is no menu item to customize them.
Reading the TouchBar documentation there are two options:
1: NSApplication
The Customization Menu Item
A user invokes the customization UI for a particular NSTouchBar object, when it is visible in the Touch Bar, by choosing the bar customization menu item. To enable this menu item you must explicitly opt-in, which you can do in the following ways:
If you want the system to automatically name, place, validate, and activate this menu item in your app’s menus, set the isAutomaticCustomizeTouchBarMenuItemEnabled property of your app object (of type NSApplication) to true.
To explicitly place the customization menu item in one of your app’s menus, employ the toggleTouchBarCustomizationPalette(_:) method of your app object. When you do this, the system still names and validates the menu item, and hides it on systems that do not have a Touch Bar.
Trying to do either of those yields a 'NSApplication' is unavailable in Mac Catalyst error.
So after some googling around I found this:
NSClassFromString("NSApplication")?.setValue(true, forKeyPath: "sharedApplication.automaticCustomizeTouchBarMenuItemEnabled")
print(NSClassFromString("NSApplication")?.value(forKeyPath: "sharedApplication.isAutomaticCustomizeTouchBarMenuItemEnabled"))
This compiles and executes fine. It even prints out Optional(1) where there was an Optional(0) before. But the menu item still is not there. I tried this at the point where I generate the TouchBar, where I generate the Menu, and in func application(_, didFinishLaunchingWithOptions), but to no avail.
I cannot get the second one to not give me an error.
2: TouchBar
Curiously the NSTouchBar has the same property, but running
NSTouchBar.isAutomaticCustomizeTouchBarMenuItemEnabled = true
at any point (which compiles, too) yields no difference.
Question
Is this a missing feature or is there a way to achieve it. And if so: how?
Edit
I am customizing the menu bar. Due to an error, setting the same shortcut for two options, causes the following output in Xcode:
2020-02-15 14:08:01.492510+0100 Myapp[71888:2189305] [MenuBuilder] Menu has duplicates --
<_UIImmutableKeyCommand: 0x60000374e700> -> Title: Toggle Center Column Action: executeOptionForKeyCommand: Input: 1 + (UIKeyModifierCommand)
<_UIImmutableKeyCommand: 0x60000374e640> -> Title: Toggle Left Column Action: executeOptionForKeyCommand: Input: 1 + (UIKeyModifierCommand)
Make a symbolic breakpoint at _UIMenuBuilderError to catch this in the debugger.
2020-02-15 14:08:01.492701+0100 Myapp[71888:2189305] *** Assertion failure in -[_UIMenuBuilder _insertMenu:intoParentMenu:newParentMenu:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3901.4.905/UIMenu/UIMenuBuilder.m:456
2020-02-15 14:08:01.492950+0100 Myapp[71888:2189305] [General] inserted menu has duplicate submenu, command or key command, or a key command is missing input or action
2020-02-15 14:08:01.497025+0100 Myapp[71888:2189305] [General] (
0 CoreFoundation 0x00007fff2f3858ab __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6563f805 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2f3aed10 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff31aa7241 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff6d31dded -[_UIMenuBuilder _insertMenu:intoParentMenu:newParentMenu:] + 1426
5 UIKitCore 0x00007fff6d31e9ef -[_UIMenuBuilder insertChildMenu:atStartOfMenuForIdentifier:] + 177
6 Myapp 0x000000010010a87b $s5Myapp11AppDelegateC9buildMenu4withySo13UIMenuBuilder_p_tF + 4987
7 Myapp 0x000000010010b150 $s5Myapp11AppDelegateC9buildMenu4withySo13UIMenuBuilder_p_tFTo + 64
8 UIKitCore 0x00007fff6d31c428 -[UIResponder _buildMenuFromChainWithBuilder:] + 115
9 UIKitCore 0x00007fff6d31c17f -[UIMenuSystem _newBuilderFromResponderChain:] + 72
10 UIKitCore 0x00007fff6d31c114 -[UIMenuSystem _automaticallyRebuildIfNeeded] + 88
11 UIKitCore 0x00007fff6d31c09e -[UIMenuSystem _rootMenu] + 27
12 UIKitCore 0x00007fff6d3144d9 -[_UIMenuBarController _rebuildRootCommandGroup] + 66
13 Foundation 0x00007fff3197ffab -[__NSObserver _doit:] + 296
14 CoreFoundation 0x00007fff2f2ff35f __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
15 CoreFoundation 0x00007fff2f2ff2f3 ___CFXRegistrationPost1_block_invoke + 63
16 CoreFoundation 0x00007fff2f2ff268 _CFXRegistrationPost1 + 372
17 CoreFoundation 0x00007fff2f2feebe ___CFXNotificationPost_block_invoke + 97
18 CoreFoundation 0x00007fff2f2ce7e2 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1575
19 CoreFoundation 0x00007fff2f2cdc82 _CFXNotificationPost + 1351
20 Foundation 0x00007fff319e6048 postQueueNotifications + 718
21 CoreFoundation 0x00007fff2f3090ee __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
22 CoreFoundation 0x00007fff2f309014 __CFRunLoopDoObservers + 457
23 CoreFoundation 0x00007fff2f308832 __CFRunLoopRun + 1514
24 CoreFoundation 0x00007fff2f307bd3 CFRunLoopRunSpecific + 499
25 HIToolbox 0x00007fff2de5d65d RunCurrentEventLoopInMode + 292
26 HIToolbox 0x00007fff2de5d39d ReceiveNextEventCommon + 600
27 HIToolbox 0x00007fff2de5d127 _BlockUntilNextEventMatchingListInModeWithFilter + 64
28 AppKit 0x00007fff2c4cdba4 _DPSNextEvent + 990
29 AppKit 0x00007fff2c4cc380 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
30 AppKit 0x00007fff2c4be09e -[NSApplication run] + 658
31 AppKit 0x00007fff2c490465 NSApplicationMain + 777
32 AppKit 0x00007fff2c7b369c _NSApplicationMainWithInfoDictionary + 16
33 UIKitMacHelper 0x00007fff602de8f1 UINSApplicationMain + 322
34 UIKitCore 0x00007fff6d186273 UIApplicationMain + 2105
35 Myapp 0x000000010010b39b main + 75
36 libdyld.dylib 0x00007fff669ad7fd start + 1
)
2020-02-15 14:08:27.979587+0100 Myapp[71888:2189305] [Layout] Unable to simultaneously satisfy constraints:
(
"<NSAutoresizingMaskLayoutConstraint:0x600002183ac0 h=-&- v=-&- _SC_RESULTS_TABLE.minY == 0 (active, names: _SC_RESULTS_TABLE:0x100dc3140, '|':SCTMenuView:0x100dca2e0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x600002183f70 h=-&- v=-&- V:|-(202)-[_SC_RESULTS_TABLE] (active, names: _SC_RESULTS_TABLE:0x100dc3140, '|':SCTMenuView:0x100dca2e0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x60000217f200 h=--& v=--& SCTMenuView:0x100dca2e0.height == 59 (active)>"
)
Will attempt to recover by breaking constraint
<NSAutoresizingMaskLayoutConstraint:0x600002183f70 h=-&- v=-&- V:|-(202)-[_SC_RESULTS_TABLE] (active, names: _SC_RESULTS_TABLE:0x100dc3140, '|':SCTMenuView:0x100dca2e0 )>
Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -[NSWindow visualizeConstraints:] automatically called when this happens. And/or, set a symbolic breakpoint on LAYOUT_CONSTRAINTS_NOT_SATISFIABLE to catch this in the debugger.
2020-02-15 14:08:29.504823+0100 Myapp[71888:2189305] [MenuBuilder] Menu has duplicates --
<_UIImmutableKeyCommand: 0x60000375e400> -> Title: Toggle Center Column Action: executeOptionForKeyCommand: Input: 1 + (UIKeyModifierCommand)
<_UIImmutableKeyCommand: 0x60000375e340> -> Title: Toggle Left Column Action: executeOptionForKeyCommand: Input: 1 + (UIKeyModifierCommand)
Make a symbolic breakpoint at _UIMenuBuilderError to catch this in the debugger.
2020-02-15 14:08:29.504936+0100 Myapp[71888:2189305] *** Assertion failure in -[_UIMenuBuilder _insertMenu:intoParentMenu:newParentMenu:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3901.4.905/UIMenu/UIMenuBuilder.m:456
2020-02-15 14:08:29.506015+0100 Myapp[71888:2189305] [General] inserted menu has duplicate submenu, command or key command, or a key command is missing input or action
2020-02-15 14:08:29.514279+0100 Myapp[71888:2189305] [General] (
0 CoreFoundation 0x00007fff2f3858ab __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6563f805 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2f3aed10 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff31aa7241 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff6d31dded -[_UIMenuBuilder _insertMenu:intoParentMenu:newParentMenu:] + 1426
5 UIKitCore 0x00007fff6d31e9ef -[_UIMenuBuilder insertChildMenu:atStartOfMenuForIdentifier:] + 177
6 Myapp 0x000000010010a87b $s5Myapp11AppDelegateC9buildMenu4withySo13UIMenuBuilder_p_tF + 4987
7 Myapp 0x000000010010b150 $s5Myapp11AppDelegateC9buildMenu4withySo13UIMenuBuilder_p_tFTo + 64
8 UIKitCore 0x00007fff6d31c428 -[UIResponder _buildMenuFromChainWithBuilder:] + 115
9 UIKitCore 0x00007fff6d31c17f -[UIMenuSystem _newBuilderFromResponderChain:] + 72
10 UIKitCore 0x00007fff6d31c114 -[UIMenuSystem _automaticallyRebuildIfNeeded] + 88
11 UIKitCore 0x00007fff6d3cf5aa -[UIMenuSystem _keyCommands] + 27
12 UIKitCore 0x00007fff6d3cf375 -[UIApplication _keyCommands] + 105
13 UIKitCore 0x00007fff6dd17069 -[UIResponder _keyCommandForEvent:target:] + 182
14 UIKitCore 0x00007fff6dd17405 -[UIResponder _keyCommandForEvent:target:] + 1106
15 UIKitCore 0x00007fff6dd17405 -[UIResponder _keyCommandForEvent:target:] + 1106
16 UIKitCore 0x00007fff6dd17405 -[UIResponder _keyCommandForEvent:target:] + 1106
17 UIKitCore 0x00007fff6dd17405 -[UIResponder _keyCommandForEvent:target:] + 1106
18 UIKitCore 0x00007fff6dd17405 -[UIResponder _keyCommandForEvent:target:] + 1106
19 UIKitCore 0x00007fff6e0a36ce -[UIApplication(iOSMacSupport) _physicalKeyEvent:unmodified:shiftModified:commandModified:modifierFlags:isDown:timestampMachAbs:] + 517
20 UIKitCore 0x00007fff6e0a3803 -[UIApplication(iOSMacSupport) _sendKeyEvent:unmodified:shiftModified:commandModified:modifierFlags:isDown:timestampMachAbs:] + 116
21 UIKitCore 0x00007fff6e0a1c38 __58-[UIApplication(iOSMacSupport) _initiateIOSMacConnections]_block_invoke_3.396 + 124
22 UIKitMacHelper 0x00007fff602f4e3c -[UINSInputView _sendKeyEvent:isDown:] + 452
23 UIKitMacHelper 0x00007fff602f4ebd -[UINSInputView keyUp:] + 47
24 AppKit 0x00007fff2c675b98 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6512
25 AppKit 0x00007fff2c674005 -[NSWindow(NSEventRouting) sendEvent:] + 349
26 AppKit 0x00007fff2c672ccf -[NSApplication(NSEvent) sendEvent:] + 2739
27 AppKit 0x00007fff2c4be0cf -[NSApplication run] + 707
28 AppKit 0x00007fff2c490465 NSApplicationMain + 777
29 AppKit 0x00007fff2c7b369c _NSApplicationMainWithInfoDictionary + 16
30 UIKitMacHelper 0x00007fff602de8f1 UINSApplicationMain + 322
31 UIKitCore 0x00007fff6d186273 UIApplicationMain + 2105
32 Myapp 0x000000010010b39b main + 75
33 libdyld.dylib 0x00007fff669ad7fd start + 1
)
2020-02-15 14:08:30.338067+0100 Myapp[71888:2189305] *** Assertion failure in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.30.142/AppKit.subproj/NSApplication.m:3694
2020-02-15 14:08:30.338318+0100 Myapp[71888:2189305] [General] Modal session requires modal window
2020-02-15 14:08:30.348833+0100 Myapp[71888:2189305] [General] (
0 CoreFoundation 0x00007fff2f3858ab __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6563f805 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2f3aed10 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff31aa7241 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 AppKit 0x00007fff2c7cf9d0 -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] + 1583
5 AppKit 0x00007fff2c7cf39b -[NSApplication beginModalSessionForWindow:] + 37
6 AppKit 0x00007fff2c7cf2fc __35-[NSApplication runModalForWindow:]_block_invoke_2 + 39
7 AppKit 0x00007fff2c7cf2c2 __35-[NSApplication runModalForWindow:]_block_invoke + 70
8 AppKit 0x00007fff2c7ceb4c _NSTryRunModal + 100
9 AppKit 0x00007fff2c7cea31 -[NSApplication runModalForWindow:] + 128
10 AppKit 0x00007fff2cd21be6 __82-[NSTouchBarCustomizationController toggleCustomizationPalette:forceControlStrip:]_block_invoke_4 + 148
11 AppKit 0x00007fff2cd244c7 ___NSRunLoopTimerCreateWithHandler_block_invoke + 34
12 CoreFoundation 0x00007fff2f324804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
13 CoreFoundation 0x00007fff2f3243be __CFRunLoopDoTimer + 859
14 CoreFoundation 0x00007fff2f323e9e __CFRunLoopDoTimers + 317
15 CoreFoundation 0x00007fff2f308aed __CFRunLoopRun + 2213
16 CoreFoundation 0x00007fff2f307bd3 CFRunLoopRunSpecific + 499
17 HIToolbox 0x00007fff2de5d65d RunCurrentEventLoopInMode + 292
18 HIToolbox 0x00007fff2de5d2a9 ReceiveNextEventCommon + 356
19 HIToolbox 0x00007fff2de5d127 _BlockUntilNextEventMatchingListInModeWithFilter + 64
20 AppKit 0x00007fff2c4cdba4 _DPSNextEvent + 990
21 AppKit 0x00007fff2c4cc380 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
22 AppKit 0x00007fff2c4be09e -[NSApplication run] + 658
23 AppKit 0x00007fff2c490465 NSApplicationMain + 777
24 AppKit 0x00007fff2c7b369c _NSApplicationMainWithInfoDictionary + 16
25 UIKitMacHelper 0x00007fff602de8f1 UINSApplicationMain + 322
26 UIKitCore 0x00007fff6d186273 UIApplicationMain + 2105
27 Myapp 0x000000010010b39b main + 75
28 libdyld.dylib 0x00007fff669ad7fd start + 1
)
2020-02-15 14:08:31.815095+0100 Myapp[71888:2189305] [AXRuntimeCommon] Unknown client: Myapp
But then the customize TouchBar action shows up in the menu (all my custom ones are gone), the ❗MISSING LABEL❗ issue is easily fixed.
So I wondered whether it was my menu customization code causing the error, but uncommenting the entire override func buildMenu(with builder: UIMenuBuilder) in my AppDelegate does not cause the customization menu to appear – only the shortcut collision does.
In my Swift Catalyst app (macOS 10.15.3, Xcode 11.3.1), I am able to call
NSTouchBar.isAutomaticCustomizeTouchBarMenuItemEnabled = true
in my override func makeTouchBar() method, and the "Customize Touch Bar..." menu item appears in the "View" menu tab. For the missing labels, the following works:
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
if identifier == yourIdentifier {
let item = NSPickerTouchBarItem(...)
item.customizationLabel = "View Segmented Control"
return item
}
return nil
}

Swift - hierarchy constraint issues and debugging

I'm new to swift and am finding debugging to be particularly difficult. I"m using RubyMotion if that is relevant. After I log out a user and try to log back in I receive the following log:
2017-04-20 13:56:54.810 nav[8614:3232848] *** Assertion failure in -[UIView _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.6.21/NSLayoutConstraint_UIKitAdditions.m:649
2017-04-20 13:56:54.927 nav[8614:3232848] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Impossible to set up layout with view hierarchy unprepared for constraint.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102ab5d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010141421e objc_exception_throw + 48
2 CoreFoundation 0x0000000102ab9e42 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001038d466d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000105a4d57b __120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2 + 206
5 UIKit 0x0000000105a4d417 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 418
6 UIKit 0x0000000105a4d7e8 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30
7 UIKit 0x0000000105a4d8fa -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 221
8 UIKit 0x0000000105a4dc0e __50-[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 208
9 Foundation 0x000000010385a3b0 -[NSISEngine withBehaviors:performModifications:] + 155
10 UIKit 0x0000000105a4db2f -[UIView(UIConstraintBasedLayout) addConstraints:] + 277
11 nav 0x00000001000d2ae2 __unnamed_64 + 98
12 nav 0x00000001004b495c vm_dispatch + 1372
13 nav 0x00000001004b8511 rb_scope__strain__ + 1313
14 nav 0x00000001009d9135 rb_vm_dispatch + 7221
15 nav 0x00000001004b495c vm_dispatch + 1372
16 nav 0x00000001004b7a3e rb_scope__initialize__ + 238
17 nav 0x00000001009d9135 rb_vm_dispatch + 7221
18 nav 0x000000010092ec57 rb_class_new_instance0 + 855
19 nav 0x00000001009d86e6 rb_vm_dispatch + 4582
20 nav 0x000000010076c1ec vm_dispatch + 1372
21 nav 0x0000000100780bc3 rb_scope__main_layout__ + 275
22 nav 0x00000001009d9135 rb_vm_dispatch + 7221
23 nav 0x000000010076c1ec vm_dispatch + 1372
24 nav 0x0000000100777955 rb_scope__layout__ + 133
25 nav 0x00000001009d9135 rb_vm_dispatch + 7221
26 nav 0x000000010076c1ec vm_dispatch + 1372
27 nav 0x0000000100778496 rb_scope__viewDidLoad__ + 534
28 nav 0x00000001007784ed __unnamed_67 + 13
29 UIKit 0x000000010522aa3d -[UIViewController loadViewIfRequired] + 1258
30 UIKit 0x0000000105231062 -[UIViewController __viewWillAppear:] + 118
31 UIKit 0x000000010525c1d3 -[UINavigationController _startCustomTransition:] + 1290
32 UIKit 0x000000010526ce48 -[UINavigationController _startDeferredTransitionIfNeeded:] + 697
33 UIKit 0x000000010526dfdb -[UINavigationController __viewWillLayoutSubviews] + 58
34 UIKit 0x0000000105464dd7 -[UILayoutContainerView layoutSubviews] + 223
35 UIKit 0x000000010514dab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
36 QuartzCore 0x0000000104b4ebf8 -[CALayer layoutSublayers] + 146
37 QuartzCore 0x0000000104b42440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
38 QuartzCore 0x0000000104b422be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
39 QuartzCore 0x0000000104ad0318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
40 QuartzCore 0x0000000104afd3ff _ZN2CA11Transaction6commitEv + 475
41 QuartzCore 0x0000000104afdd6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
42 CoreFoundation 0x0000000102a5a267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
43 CoreFoundation 0x0000000102a5a1d7 __CFRunLoopDoObservers + 391
44 CoreFoundation 0x0000000102a3ef8e __CFRunLoopRun + 1198
45 CoreFoundation 0x0000000102a3e884 CFRunLoopRunSpecific + 420
46 GraphicsServices 0x0000000107e57a6f GSEventRunModal + 161
47 UIKit 0x0000000105088c68 UIApplicationMain + 159
48 nav 0x00000001000a9fd2 main + 146
49 libdyld.dylib 0x0000000106f1b68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
What I'm struggling with is trying to find out where the error is in my code from the error logs.
Perhaps I'm spoiled but in ruby I'm used to a filename and line number being given where the error has been caused - is this something I can find out from this log?
Thanks in advance.

caught non-fatal NSInvalidArgumentExecption in -[NSScrollView reloadData]

I have built a document based app in swift and then I added a NSCollectionView to it with an add button next to it. The button would call a NSOpenPanel and then the icon of the item chosen should appear in the collection view. However, when I click the 'open' button in the NSOpenPanel, the following were printed to the console:
2017-01-30 19:36:54.205343 CookRecipes[5004:203650] -[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770
2017-01-30 19:36:54.224746 CookRecipes[5004:203650] -[NSVBSavePanel didEndPanelWithReturnCode:] caught non-fatal NSInvalidArgumentException '-[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770' with backtrace (
0 CoreFoundation 0x00007fff9e2010db __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb2e92a2a objc_exception_throw + 48
2 CoreFoundation 0x00007fff9e281cd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff9e1742a3 ___forwarding___ + 1059
4 CoreFoundation 0x00007fff9e173df8 _CF_forwarding_prep_0 + 120
5 CookRecipes 0x0000000100004239 _TFFC11CookRecipes8Document7addFileFT_T_U_FSiT_ + 457
6 CookRecipes 0x00000001000047ef _TTRXFo_dSi__XFdCb_dSi__ + 47
7 AppKit 0x00007fff9c0665e4 -[NSVBSavePanel didEndPanelWithReturnCode:] + 68
8 AppKit 0x00007fff9c6ba09d -[NSVBSavePanel completeModeless:] + 74
9 AppKit 0x00007fff9befa721 -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] + 597
10 Foundation 0x00007fff9fbcb71d NSKeyValueNotifyObserver + 350
11 Foundation 0x00007fff9fbcafb4 NSKeyValueDidChange + 486
12 Foundation 0x00007fff9fb99e96 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
13 ViewBridge 0x00007fffb184c066 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 447
14 ViewBridge 0x00007fffb18d052b withHintInProgress + 487
15 ViewBridge 0x00007fffb184be83 -[NSViewBridge setObject:forKey:withKVO:] + 1014
16 ViewBridge 0x00007fffb184a95a -[NSViewBridge nonLocalChangeInProgress:block:] + 390
17 ViewBridge 0x00007fffb18aa260 -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 256
18 ViewBridge 0x00007fffb18aa3e8 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
19 CoreFoundation 0x00007fff9e1756dc __invoking___ + 140
20 CoreFoundation 0x00007fff9e175561 -[NSInvocation invoke] + 289
21 ViewBridge 0x00007fffb18d052b withHintInProgress + 487
22 ViewBridge 0x00007fffb18d025a __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
23 ViewBridge 0x00007fffb1851df2 +[NSViewServiceApplication withHostPID:invoke:] + 46
24 ViewBridge 0x00007fffb18d011d __deferNSXPCInvocationOntoMainThread_block_invoke + 179
25 ViewBridge 0x00007fffb18cfd0a __deferBlockOntoMainThread_block_invoke_2 + 544
26 CoreFoundation 0x00007fff9e19771c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
27 CoreFoundation 0x00007fff9e1789d4 __CFRunLoopDoBlocks + 356
28 CoreFoundation 0x00007fff9e178516 __CFRunLoopRun + 1894
29 CoreFoundation 0x00007fff9e177b54 CFRunLoopRunSpecific + 420
30 HIToolbox 0x00007fff9d702a5c RunCurrentEventLoopInMode + 240
31 HIToolbox 0x00007fff9d702891 ReceiveNextEventCommon + 432
32 HIToolbox 0x00007fff9d7026c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
33 AppKit 0x00007fff9bca85b4 _DPSNextEvent + 1120
34 AppKit 0x00007fff9c422d6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
35 AppKit 0x00007fff9bc9cf35 -[NSApplication run] + 926
36 AppKit 0x00007fff9bc67850 NSApplicationMain + 1237
37 CookRecipes 0x000000010000c344 main + 84
38 libdyld.dylib 0x00007fffb3774255 start + 1
39 ??? 0x0000000000000003 0x0 + 3
)
2017-01-30 19:36:54.239473 CookRecipes[5004:203650] -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] caught non-fatal NSInvalidArgumentException '-[NSScrollView reloadData]: unrecognized selector sent to instance 0x6180001c1770' with backtrace (
0 CoreFoundation 0x00007fff9e2010db __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb2e92a2a objc_exception_throw + 48
2 CoreFoundation 0x00007fff9e281cd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff9e1742a3 ___forwarding___ + 1059
4 CoreFoundation 0x00007fff9e173df8 _CF_forwarding_prep_0 + 120
5 CookRecipes 0x0000000100004239 _TFFC11CookRecipes8Document7addFileFT_T_U_FSiT_ + 457
6 CookRecipes 0x00000001000047ef _TTRXFo_dSi__XFdCb_dSi__ + 47
7 AppKit 0x00007fff9c0665e4 -[NSVBSavePanel didEndPanelWithReturnCode:] + 68
8 AppKit 0x00007fff9c6ba09d -[NSVBSavePanel completeModeless:] + 74
9 AppKit 0x00007fff9befa721 -[NSVBSavePanel observeValueForKeyPath:ofObject:change:context:] + 597
10 Foundation 0x00007fff9fbcb71d NSKeyValueNotifyObserver + 350
11 Foundation 0x00007fff9fbcafb4 NSKeyValueDidChange + 486
12 Foundation 0x00007fff9fb99e96 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
13 ViewBridge 0x00007fffb184c066 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 447
14 ViewBridge 0x00007fffb18d052b withHintInProgress + 487
15 ViewBridge 0x00007fffb184be83 -[NSViewBridge setObject:forKey:withKVO:] + 1014
16 ViewBridge 0x00007fffb184a95a -[NSViewBridge nonLocalChangeInProgress:block:] + 390
17 ViewBridge 0x00007fffb18aa260 -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 256
18 ViewBridge 0x00007fffb18aa3e8 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
19 CoreFoundation 0x00007fff9e1756dc __invoking___ + 140
20 CoreFoundation 0x00007fff9e175561 -[NSInvocation invoke] + 289
21 ViewBridge 0x00007fffb18d052b withHintInProgress + 487
22 ViewBridge 0x00007fffb18d025a __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
23 ViewBridge 0x00007fffb1851df2 +[NSViewServiceApplication withHostPID:invoke:] + 46
24 ViewBridge 0x00007fffb18d011d __deferNSXPCInvocationOntoMainThread_block_invoke + 179
25 ViewBridge 0x00007fffb18cfd0a __deferBlockOntoMainThread_block_invoke_2 + 544
26 CoreFoundation 0x00007fff9e19771c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
27 CoreFoundation 0x00007fff9e1789d4 __CFRunLoopDoBlocks + 356
28 CoreFoundation 0x00007fff9e178516 __CFRunLoopRun + 1894
29 CoreFoundation 0x00007fff9e177b54 CFRunLoopRunSpecific + 420
30 HIToolbox 0x00007fff9d702a5c RunCurrentEventLoopInMode + 240
31 HIToolbox 0x00007fff9d702891 ReceiveNextEventCommon + 432
32 HIToolbox 0x00007fff9d7026c6 _BlockUntilNextEventMatchingListInModeWithFilter + 71
33 AppKit 0x00007fff9bca85b4 _DPSNextEvent + 1120
34 AppKit 0x00007fff9c422d6b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2789
35 AppKit 0x00007fff9bc9cf35 -[NSApplication run] + 926
36 AppKit 0x00007fff9bc67850 NSApplicationMain + 1237
37 CookRecipes 0x000000010000c344 main + 84
38 libdyld.dylib 0x00007fffb3774255 start + 1
39 ??? 0x0000000000000003 0x0 + 3
)
I think that the code that the problem is in should be in this segment:
extension Document : AddAttachmentDelegate {
internal func addFile() {
let panel = NSOpenPanel()
panel.allowsMultipleSelection = false
panel.canChooseDirectories = false
panel.canChooseFiles = true
panel.begin { (result) -> Void in
if result == NSModalResponseOK, let resultURL = panel.urls.first {
do {
try self.addAttachmentAtURL(url: resultURL)
self.attachmentsList?.reloadData()
} catch let error as NSError {
if let window = self.windowForSheet {
NSApp.presentError(error, modalFor: window, delegate: nil, didPresent: nil, contextInfo: nil)
} else {
NSApp.presentError(error)
}
}
}
}
}
}
I have no idea what is going on. Hope you can help.
EDIT: attachmentsList is connected by the following:
#IBOutlet weak var attachmentsList: NSCollectionView!

Proper parameters for closeAllDocumentsWithDelegate

I am writing an app that needs to have multiple documents in one window (as was asked about here. So I can't just make it a "document-based application", but I am still trying to use the document architecture to save the individual files.
What I'm specifically trying to do is close all open documents, and preferably save them if they have been modified. It seems like the best way to do this is to call the closeAllDocumentsWithDelegate method of the shared document controller. But I don't know what parameters to pass it. The docs say it is:
func closeAllDocumentsWithDelegate(_ delegate: AnyObject?,
didCloseAllSelector didCloseAllSelector: Selector,
contextInfo contextInfo: UnsafeMutablePointer)
They don't say what these mean, though. What delegate, selector and contextInfo should I be calling? I can't find examples of this method being used successfully. I tried seeing if I could get away with self and nil just to get it to compile:
SharedDocumentController.sharedDocumentController().closeAllDocumentsWithDelegate(self, didCloseAllSelector: nil, contextInfo: nil)
But then I get the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)", which I'm told is a null pointer exception. So at least one of those nils is a no-go, probably because of a forced unwrap somewhere. Fine, but what would I put there instead?
EDIT: as requested below, I am attaching a pic of the stacktrace:
And of the console:
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
This method simply executes -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: for all open windows. So look at its documentation. (Linked above.)
The short form: You can pass a delegate object, which will be informed about the close request via the method that responds to the selector, you passed.
So let's say, the object that should be informed is the app delegate, then you pass this as delegate parameter and write a method in the app delegate, whose selector you pass as selector parameter. In Swift you must decorate that method (Swift: function) with #objc.
The contextInfo is any user-definable data to pass or not. It is simply passed through. It is a "communication channel" from caller in your code to the delegate method, i. e. signaling the reason for the close. You can pass nil for it.
Even I did not test it, but typically you can pass nil for delegate, too. In such a case you should be able to pass NULL (it is no type) for the selector. Just try it. Then you do not need an empty method.