XCode4 - 在哪里查找由核心数据创建的sqlite文件 [英] XCode4 - where to look for sqlite file created by core data

查看:165
本文介绍了XCode4 - 在哪里查找由核心数据创建的sqlite文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用核心数据。我想设置一个预填充的数据库。我读某处,当核心数据应用程序运行时,核心数据创建一个sqlite文件。我不知道在哪里找它。



我按照 blog ,但没有找到sqlite文件的位置指定目录 / Users /<用户名> /库/应用程序支持/ iPhone模拟器/用户/应用程序/<应用程序GUID> / Documents /< database name.sqlite> 也不在应用程序目录中。



这里是我的用于persistentCoordinator的代码。

   - (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{
if(__persistentStoreCoordinator!= nil)
{
return __persistentStoreCoordinator;
}

NSString * storePath = [[[self applicationDocumentsDirectory] ​​path] stringByAppendingPathComponent:@coredata.sqlite];
NSFileManager * fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:storePath]){
NSString * defaultStorePath = [[NSBundle mainBundle] pathForResource:@coredataofType:@sqlite];
if(defaultStorePath){
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}

NSURL * storeURL = [NSURL fileURLWithPath:storePath];
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,[NSNumber numberWithBool:YES],NSInferMappingModelAutomaticallyOption,nil];

NSError * error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if(![__ persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:& error])
{
NSLog(@Unresolved error%@,%@ error,[error userInfo]);
abort();
}

return __persistentStoreCoordinator;
}


解决方案

c / c> c / c / c / c / c / c / c / c / c / c / c / c / b
$ b

如果您有多个SDK,请务必查看您的应用程序的所有不同的SDK版本目录。


I have just started using core data. I want to setup a pre-populated db. I read somewhere that core data creates a sqlite file when a core data app is run. I don't know where to look for it though.

I followed the instructions over on this blog but did not find the sqlite file over the location specified directory /Users/<Username>/Library/Application Support/iPhone Simulator/User/Application/<Application GUID>/Documents/<database name.sqlite> nor in the application directory.

here is my code for persistentCoordinator.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSString *storePath = [[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:@"coredata.sqlite"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:storePath]) {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"coredata" ofType:@"sqlite"];
        if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
        }
    }

    NSURL *storeURL = [NSURL fileURLWithPath:storePath];
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}

解决方案

Those files are in ~/Library/Application Support/iPhone Simulator/[SDK version]/Applications/[App GUID]/Documents for me, both for Xcode 3 and Xcode 4.

If you have multiple SDKs, make sure to look in all the different SDK version directories for your app.

这篇关于XCode4 - 在哪里查找由核心数据创建的sqlite文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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