LoginSignup
2
2

More than 3 years have passed since last update.

新規作成したmacOS CoreDataアプリでデータが保存されない場合の設定

Last updated at Posted at 2019-10-22

この記事ではmacOS Catalina 10.15、Xcode 11.1を使用しています。
初心者で、初めての投稿です。

アプリ終了時にデータが保存されない?

Xcode 11.1を使って、Core Dataのシンプルなテストアプリを作ってみたところ、アプリ終了時にデータが保存されない現象が発生しました。

macOS Catalinaにアップデートする前は問題なく動作した手順だったのですが、Custom macOS Application Target Propertiesに新たな設定が追加されていて、それが影響しているようでした。

追加されていたのは、次の2つのKeyです。Targetの、Infoタブにあります。

Key Value
Application can be killed immeditately when user is shutting down or logging out YES
Application can be killed to reclaim memory or other extraordinary circumstances YES

たぶん、このせいで、Quit時に

AppDelegate.swift
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {}

が呼び出されていないようです。

これらをNOに設定することで、データは保存されるようになりました。

データの保存場所(App Sandboxの設定)

ただ、データの保存場所が、ライブラリ\Application Supportから、ライブラリ\Containersに変更になっていました。もしかしたらCatalina以前から変更になっていたのかもしれませんが、これは(アプリ名).entitlementsファイルの設定が

Key Value
App Sandbox YES

になっているからでした。

2
2
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
2
2