Swift CoreDataの中身を確認する方法

まずappdelegateに記載する アプリが起動したら呼ばれるところ

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { print("AppDelegate.application()")
let path = NSSearchPathForDirectoriesInDomains( .applicationSupportDirectory, .userDomainMask,true).first! print("- applicationSupportDirectory:(path)") return true }

NSFileManagerクラスのこの関数を利用する

NSSearchPathForDirectoriesInDomains

このクラスは,ファイルやディレクトリの検索、作成、コピー、および移動を行います。また、ファイルやディレクトリに関する情報を取得したり、属性の一部を変更したりするためにも使用します。 この関数は、指定されたドメイン内の指定されたディレクトリのパス文字列のリストを作成します。

定義

public func NSSearchPathForDirectoriesInDomains(_ directory: FileManager.SearchPathDirectory, _ domainMask: FileManager.SearchPathDomainMask, _ expandTilde: Bool) -> [String]

SearchPathDirectoryは列挙体です。その中に .applicationDirectory があります。

public struct SearchPathDomainMask の構造体の中には、 public static var userDomainMask: FileManager.SearchPathDomainMask { get } // user's home directory --- place to install user's personal items (~ ここを見るとユーザーの個人的ファイル、ここではcoredataへのパスが取得できます。

print("- applicationSupportDirectory:(path)")

これでログにはいています。 f:id:happy_teeth_ago:20180702171407p:plain

場所がわかったらDB接続してみていきましょう。 おすすめのアプリはDBBrowser for SQLiteです。MAC版ですし、無料で使いやすいです。 f:id:happy_teeth_ago:20180702171543p:plain