Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

swift - Core Data file's Location iOS 10

I am trying to us SQLite Browsers to see my Core Data objects. I am not able to find where does the core data save its sql file. I looked into the app documents folder but there is nothing there.

Do you know where does the core data in IOS 10(simulator) save its SQLite files on?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I tested it on XCode 8 Swift 3 OS macOS Sierra

IOS 10

In Your Appdelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
     print(urls[urls.count-1] as URL)

    return true
}

1. The constant .documentDirectory says we are looking for Document directory

2. The constant .userDomainMask to restrict our search to our application's sandbox.

output

file:///Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Data/Application/3B373C93-71A2-46E9-8AF7-EF407C39429F/Documents/

Click on Go -> Go to Folder -> Paste Path -> Hit Enter

enter image description here

Then Go to Library -> Application Support -> filename.sqlite

enter image description here

Edited

OR

open your terminal and type find ~ -name 'HitTest.sqlite' and hit enter.

Ashoks-MacBook-Pro:Desktop Ashok$ find ~ -name 'HitTest.sqlite'
/Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Data/Application/3B373C93-71A2-46E9-8AF7-EF407C39429F/Documents/HitTest.sqlite

From above output you can clearly see the path of your sqlite db

You can use DB Browser for SQLite to open.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...