Ida*_*viv 14 core-data ios ios-simulator swift ios10
我正在尝试使用SQLite浏览器来查看我的Core Data对象.我无法找到核心数据保存其sql文件的位置.我查看了应用程序文档文件夹但没有任何内容.
您知道IOS 10(模拟器)中的核心数据在哪里保存其SQLite文件吗?
Ash*_*k R 29
我在XCode 8 Swift 3 OS macOS Sierra上进行了测试
IOS 10
在您的Appdelegate.swif ŧ
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
}
Run Code Online (Sandbox Code Playgroud)
常数.documentDirectory说我们正在寻找文件目录
2.将.userDomainMask搜索限制在应用程序沙箱中的常量.
产量
file:///Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Data/Application/3B373C93-71A2-46E9-8AF7-EF407C39429F/Documents/
Run Code Online (Sandbox Code Playgroud)
单击Go - > Go to Folder - > Paste Path - >按Enter键
然后转到库 - >应用程序支持 - > filename.sqlite
编辑
要么
打开你的终端并键入find ~ -name 'HitTest.sqlite'并按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
Run Code Online (Sandbox Code Playgroud)
从上面的输出中,您可以清楚地看到sqlite db的路径
您可以使用DB Browser for SQLite打开.
Jit*_*odi 13
试试这个我还没有在ios 10上查看它,但它在以前的所有版本中工作
Product> Scheme> Edit Scheme> Run> Arguments
添加这种说法在" 传承启动参数 "
-com.apple.CoreData.SQLDebug 1
每次应用程序启动时它都会打印到数据库的路径 请参见此参数如下所示
Swift 3.x
在AppDelegate文件中找到didFinishLaunchingWithOptions并添加此行.
let path = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)
print("\(path)")
Run Code Online (Sandbox Code Playgroud)
对于迅捷5
func getCoreDataDBPath() {
let path = FileManager
.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)
.last?
.absoluteString
.replacingOccurrences(of: "file://", with: "")
.removingPercentEncoding
print("Core Data DB Path :: \(path ?? "Not found")")
}
Run Code Online (Sandbox Code Playgroud)
这将给出 sqlite 文件(dbname.sqlite)的详细路径
print("CoreData path :: \(self.getCoreDataDBPath())")
Run Code Online (Sandbox Code Playgroud)
注意:单击“转到”->“转到文件夹”->“在此处粘贴路径”->“输入”
| 归档时间: |
|
| 查看次数: |
16930 次 |
| 最近记录: |