LoginSignup
5
4

More than 5 years have passed since last update.

macOS向けのアプリを作ろうとして、ファイルが保存できないときの対処方法

Last updated at Posted at 2017-10-30

オライリーのLearning Swift 2nd EditionのPart IIを写経していたらちょっとハマったので備忘録。

プロジェクト開始時に"Create Document-Based Application"のチェックをONにしています。

現象としてはファイル名の入力ダイアログは表示されるが、ファイル名が入力できないうえに保存場所も指定できない状態。

デバッグログの表示画面には以下のようなメッセージが表示される。

*** Assertion failure in -[NSVBSavePanel viewWillInvalidate:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.0.100/Nav.subproj/OpenAndSavePanelRemote/NSVBOpenAndSavePanels.m:387
2017-10-31 04:17:45.645317+0900 Notes[50506:2843650] -[NSVBSavePanel init] caught non-fatal NSInternalInconsistencyException 'bridge absent' with backtrace (
    0   CoreFoundation                      0x00007fff541a132b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fff7ab35942 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff541a6f12 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x00007fff5629b690 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   AppKit                              0x00007fff519a01f6 -[NSVBSavePanel viewWillInvalidate:] + 188
    5   ViewBridge                          0x00007fff78422cb3 -[NSRemoteView invalidate:] + 292
    6   ViewBridge                          0x00007fff78430449 -[NSRemoteView _advanceToConfigPhaseLegacy] + 1111
    7   ViewBridge                          0x00007fff784312dc -[NSRemoteView _viewServiceMarshalProxy:withDetailedErrorHandler:] + 230
    8   ViewBridge                          0x00007fff78

 環境

書き忘れていたので追記。

  • macOS High Sierra (10.13)
  • Xcode 9.0
  • Swift 4

対処方法

App Sandboxという機構に妨害されているだけなのでCapabilities で"App Sandbox"という項目の”File Access"->"User Selected File
"をReade/Writeに変更するだけ。

変更前

スクリーンショット 2017-10-31 4.19.18.png

変更後

modifed_capabilities.png

  1. "User Selected File"という項目を"Read Only"から"Read/Write"に変更
  2. "App Sandbox entitlement"云々という警告が表示されるので"Fix Issue"を押す

スクリーンショット 2017-10-31 4.19.45.png

その他

上記の手順でダメな時は、関係がありそうな変数なりメソッド名に@objc、あるいはクラス定義の前に@objcMembersを記述する。

参考

そのものズバリ解決策が書いてあった。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4