XCode4 - wo kann man für sqlite-Datei, die erstellt wird von core data

Ich habe gerade angefangen mit core data. Ich möchte das setup eine pre-besiedelten db. Ich habe irgendwo gelesen, dass core data erstellt eine sqlite-Datei, wenn ein Kern Daten-app ausgeführt wird. Ich weiß nicht, wo suchen, wenn für Sie.

Folgte ich den Anweisungen auf dieser blog aber nicht zu finden, die die sqlite-Datei über den Speicherort angegebene Verzeichnis /Users/<Username>/Library/Application Support/iPhone Simulator/User/Application/<Application GUID>/Documents/<database name.sqlite> noch in dem Verzeichnis der Anwendung.

hier ist mein code für 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;
}
InformationsquelleAutor vikmalhotra | 2011-06-28
Schreibe einen Kommentar