在Sandbox中使用Cocoa NSSavePanel会导致断言失败

时间:2017-12-23 17:14:43

标签: swift xcode macos cocoa nssavepanel

我尝试使用NSSavePanel并将此行添加到我的代码中。

let test = NSSavePanel()

每次调用此代码时,都会显示此错误。 我不太清楚这里发生了什么,因为我只创建了一个新对象。 任何帮助赞赏。 谢谢!

*** 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
)

1 个答案:

答案 0 :(得分:58)

File Access类型的User Selected File权限可能仍设置为默认Read Only

  1. 导航到'功能'目标标签
  2. enter image description here

    1. User Selected File权限设置为Read/Write
    2. enter image description here

      1. 运行您的应用(bridge absent错误应该消失)