0

首先,对不起。我英语说的不好。你好。我是iOS的初学者。

目前我是这样开发的:

  1. 删除自动生成的核心数据 sqlite 文件
  2. 使用 firefox sqlite manager 将我创建的 sqlite 文件复制到已删除的 sqlite 文件路径
    (使用 Z_PK、Z_ENT、Z_OPT 的 sqlite)

两个问题:

  1. 如何使用 firefox sqlite manager 创建实体关系。
  2. 如何预先创建详细的核心数据选项,如关系删除规则、sqlite 管理器上的属性属性或其他任何东西。
4

2 回答 2

0

好吧,基本上您需要获取一个由项目使用您的模式创建的空数据库,然后对其进行操作以保存您想要的数据。更多信息在这里

链接中未描述的替代方法是使用 Core Data 本身(以及用于读取其他数据库的 SQLite 库)将数据从数据库复制到 Core Data 数据库中。

于 2013-03-15T04:10:03.260 回答
0
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (_persistentStoreCoordinator != nil) {
    return _persistentStoreCoordinator;
}

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataBooks.CDBStore"];

/*
 Set up the store.
 For the sake of illustration, provide a pre-populated default store.
 */
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn’t exist, copy the default store.
if (![fileManager fileExistsAtPath:[storeURL path]]) {
    NSURL *defaultStoreURL = [[NSBundle mainBundle] URLForResource:@"CoreDataBooks" withExtension:@"CDBStore"];
    if (defaultStoreURL) {
        [fileManager copyItemAtURL:defaultStoreURL toURL:storeURL error:NULL];
    }
}

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

NSError *error;
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

     Typical reasons for an error here include:
     * The persistent store is not accessible;
     * The schema for the persistent store is incompatible with current managed object model.
     Check the error message to determine what the actual problem was.


     If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

     If you encounter schema incompatibility errors during development, you can reduce their frequency by:
     * Simply deleting the existing store:
     [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

     * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
     @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

     Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return _persistentStoreCoordinator;

代码取自 Apple 文档 Core Data Books Link 您需要有一个预先填充的数据数据库,该数据库已通过 Core Data 填充。此函数在应用首次启动时将预填充的数据库复制到主数据库存储位置。


于 2013-03-27T02:09:07.710 回答