xcode 如何在我的 iPhone 上运行的应用程序中浏览核心数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16005544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to browse Core Data in my app running on my iPhone?
提问by Vlad
I'm working on an iPhone project that uses core data and trying to figure out a way to browse easily how data is being stored. Specifically, I am storing images in core data, and want to see how much space they're taking up, etc.
我正在开发一个使用核心数据的 iPhone 项目,并试图找出一种轻松浏览数据存储方式的方法。具体来说,我将图像存储在核心数据中,并想查看它们占用了多少空间等。
I've found an app called "Core Data Editor" that lets you browse core data on an iPhone simulator, but it's not really useful in my case since, I am storing images taken from camera. Is there a way to easily browse what is being stored on my app?
我找到了一个名为“核心数据编辑器”的应用程序,它可以让您在 iPhone 模拟器上浏览核心数据,但在我的情况下它并不是很有用,因为我正在存储从相机拍摄的图像。有没有办法轻松浏览我的应用程序中存储的内容?
采纳答案by Kendall Helmstetter Gelner
PonyDebuggeris the tool you need, it lets you browse your Core Data store and many other aspects of your running application. It's free, just download, add to your app, and run the local server on your development computer that Pony Debugger talks to.
PonyDebugger是您需要的工具,它可以让您浏览您的 Core Data 存储和正在运行的应用程序的许多其他方面。它是免费的,只需下载、添加到您的应用程序中,然后在 Pony Debugger 与之对话的开发计算机上运行本地服务器。
回答by Sixten Otto
If you don't need to see this information in real time, Xcode's Organizer will allow you to download the sandbox directory of any development apps on the device:
如果您不需要实时查看此信息,Xcode 的 Organizer 将允许您下载设备上任何开发应用程序的沙箱目录:
- Connect the device to your Mac.
- Open Xcode's Organizer window to the Devices tab.
- In the source list, select the Applications item under your device.
- Pick your application from the list in the main part of the window.
- Use the Download button at the bottom of the window to copy the sandbox directory to your Mac.
- The data is downloaded in a package, so right-click it in the Finder, and select Show Package Contents.
- 将设备连接到 Mac。
- 打开 Xcode 的管理器窗口到设备选项卡。
- 在源列表中,选择设备下的应用程序项。
- 从窗口主要部分的列表中选择您的应用程序。
- 使用窗口底部的“下载”按钮将沙箱目录复制到您的 Mac。
- 数据以包的形式下载,因此在 Finder 中右键单击它,然后选择“显示包内容”。
From there, any of the many tools available to open/inspect Core Data storage or SQLite databases should work for you.
从那里开始,可用于打开/检查 Core Data 存储或 SQLite 数据库的许多工具中的任何一个都应该适合您。
You can also use this package when running your app in the simulator or on the device to force the run into a known state. That can be tremendously helpful when debugging things like Core Data migrations or strange invalid states.
您还可以在模拟器或设备上运行您的应用程序时使用此包,以强制运行进入已知状态。这在调试诸如核心数据迁移或奇怪的无效状态之类的事情时非常有用。
回答by DontKnow
To view Coredata from a device :
要从设备查看 Coredata:
Plug in the device -
插入设备 -
Start Xcode
启动Xcode
On the top Xcode menu -
在顶部 Xcode 菜单上 -
Select Window -
选择窗口 -
Select Devices -
选择设备 -
Select your device -
选择您的设备 -
Select the app -
选择应用程序 -
Select the settings icon (gear shaped symbol to the right of "+ -") -
选择设置图标(“+ -”右侧的齿轮状符号)-
Select Download container -
选择下载容器 -
Save it to a folder -
将其保存到一个文件夹 -
It will have an extension of ".xcappdata" -
它将具有“.xcappdata”的扩展名 -
Open FireFox
打开火狐
(If you dont already have it - get the FireFox SQLite Manager browser plug in) Select the SQLite Manager icon on the top right (looks like a barrel with stripes)
(如果您还没有它 - 获取 FireFox SQLite Manager 浏览器插件)选择右上角的 SQLite Manager 图标(看起来像带条纹的桶)
Select the open folder icon
选择打开文件夹图标
change Format [SQLite DB files] to All Files
将格式 [SQLite DB 文件] 更改为所有文件
Browse to and Select your database
浏览并选择您的数据库
In addition to the tables and columns (sorry - Entities and Attributes ) you created in Coredata - you will see a few extra columns created by CoreData itself.
除了您在 Coredata 中创建的表和列(抱歉 - Entities 和 Attributes )之外 - 您还会看到一些由 CoreData 本身创建的额外列。
Hope this helps somebody. It's a bit of a bear, but worth the trouble to see your database "in the flesh"
希望这可以帮助某人。这有点熊,但值得麻烦的是看到你的数据库“肉体”
回答by RegularExpression
Find the location of the sqlite database on your sim.
在 SIM 卡上找到 sqlite 数据库的位置。
Then, in Terminal, use a command like this:
然后,在终端中,使用如下命令:
sqlite3 myDataBase.sqlite
At the prompt sqlite>
, type
在提示符下sqlite>
,键入
.dump
On the simulator, it will be located somewhere like:
在模拟器上,它将位于以下位置:
~/Library/Application Support/iPhone Simulator/[OS version]/Applications/[appGUID]/
~/Library/Application Support/iPhone Simulator/[OS version]/Applications/[appGUID]/