如何检查Core Data使用了多少磁盘空间? [英] How to check how much disk space Core Data is using?

查看:89
本文介绍了如何检查Core Data使用了多少磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用sqlite类型的持久性存储的核心数据应用程序,我知道表和数据存储在设备上的某个位置。

I am writing a core data app that uses an sqlite-type persistent store and I know the tables and the data are stored somewhere on the device.

是吗可以检查核心数据用于存储对象的内存量?

Is it possible to check how much memory Core Data is using to store objects? Maybe by checking the size of the sqlite db files?

如果可能的话,怎么办?我真的可以使用您的想法

If possible, how? I could really use your ideas

推荐答案

这取决于您使用的xcode

It depends on the xcode you are using

ios8

In ios8

它存储在


/库/开发人员/ CoreSimulator /设备/(数字和
个字母)/数据/容器/数据/应用程序/(数字和
字母)/文档/

/ Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

(数字和字母)代表的文件夹对于您的应用程序/计算机而言是唯一的,但看起来像这样:779AE2245-F8W2-57A9-8C6D-98643B1CF01A

(numbers and letters) stands for a folder that would be unique to your app/computer, but would look like this: 779AE2245-F8W2-57A9-8C6D-98643B1CF01A

您可以通过将以下方法写入 appDelegate.m,

You can do by writing below method intoappDelegate.m,

方法,并NSLogging返回路径,如下所示:

method, and NSLogging the return path, like this:

// Returns the URL to the application's Documents directory.
- (NSURL *)applicationDocumentsDirectory
{
    NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory  inDomains:NSUserDomainMask] lastObject]);

    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
 }

它将为您提供个文档模拟器上的目录网址。然后转到查找器 Cmd + Shift + G 并在此处键入此地址,即可导航到 sqlite 核心数据用来存储您的应用程序数据的文件

It will give you document directory url on simulator.Than go to finder Cmd+Shift+G and type this address here you can navigate to sqlite files which used by core data to store the data of your app

用于存储Xcode 3,Xcode 4和用于Xcpde 5的文件


〜//图书馆/应用程序支持/ iPhone模拟器/ [SDK
版本] / Applications / [App GUID] / Documents

~/Library/Application Support/iPhone Simulator/[SDK version]/Applications/[App GUID]/Documents

编辑,您可以使用以下代码检查 sqlite数据库的大小核心数据。我认为它在所有情况下都可以使用,但我不确定,我也没有验证其准确性。但是,我认为这是提供检查<$ c的顶级详细信息的一种方法$ c> coredata db的编程大小

EDIT You can use following code for check the size of your sqlite db of core data.I think it will work in all cases but i am not sure and also i do not verified its acuuracy.But i think it is one way to give top level details of checking the coredata db size programmatically

-(NSUInteger)calculate{

    //Check where you are making the sqlite
    NSURL *url = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"yourPersistentStoreName"];
    NSUInteger sizeOfData = [[NSData dataWithContentsOfURL:url] length];
    NSLog(@"sizeOfDAta in bytes %lu",(unsigned long)sizeOfData);

    return sizeOfData; 
}

这篇关于如何检查Core Data使用了多少磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆