LoginSignup
2
2

More than 5 years have passed since last update.

CoreDataで生成されたSQLite3をターミナルで直接操作する(XCode7.2 / SWift2.1.1)

Last updated at Posted at 2016-01-28

CoreDataを仕様したプロジェクトで実際のデータの値を見たかったので、メモしておきます。
実機ではなく、シミュレータでデバッグします。

① AppDelegate.swift編集
自動生成されたAppDelegate.swiftの77行目に、print(url)追加
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SingleViewCoreData.sqlite")
print(url)

② ViewControllerとかのviewDidLoad()等にコード追加
let coodinator = (UIApplication.sharedApplication().delegate as! AppDelegate).persistentStoreCoordinator
print(coodinator)

③ シミュレータでデバッグ開始
Macにsqliteファイルが生成される

④ 出力された文字列コピー
file:///Users/◯◯◯◯◯/Library/Developer/CoreSimulator/Devices/DF335499-64AE-47AE-8E99-F5333C17CA8E/data/Containers/Data/Application/1E63EEF3-E65A-492D-9F03-87657A543D45/Documents/SingleViewCoreData.sqlite

⑤ ターミナルに貼り付けて実行
sqlite3 /Users/◯◯◯◯◯/Library/Developer/CoreSimulator/Devices/DF335499-64AE-47AE-8E99-F5333C17CA8E/data/Containers/Data/Application/1E63EEF3-E65A-492D-9F03-87657A543D45/Documents/SingleViewCoreData.sqlite

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