CoreData : Ende im Gelände

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • CoreData : Ende im Gelände

    Hallo, zwei Fragen dazu,
    Ab welchem Punkt darf ich ein Entity editieren bevor ich die Meldung bekomme :
    [b]reason=The model used to open the store is incompatible with the one used to create the store[/b]

    Ein Problem mit LeichtWeightMigration :
    Code von Apple.

    Quellcode

    1. -(void)lightweightMigration
    2. {
    3. NSURL * storeURL; // ??
    4. NSManagedObjectModel * mom = [self managedObjectModel];
    5. NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
    6. NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES};
    7. NSError *error = nil;
    8. if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
    9. {
    10. NSAssert(NO, @"Unable to load persistent store: %@\n%@",
    11. [error localizedDescription], [error userInfo]);
    12. NSLog(@"%@ \n",[error localizedDescription]);
    13. NSLog(@"%@ \n",[error userInfo]);
    14. }
    15. }
    Alles anzeigen
    Ich weiss nicht wie ich storeURL bekomme. =O
    Gruss an meine Verehrer ;)
    Uwe
    Als ich ein kleiner Junge war, habe ich mir gedacht: Wenn ich groß bin möchte ich so sein wie ich.
  • Aber Du legst den Store doch selber an bzw. referenzierst ihn in Deiner Methode, die den persistentStoreCoordinator liefert. Dann kannst Du die URL doch leicht ermitteln. Bei mir sieht es zum Bespiel so aus:

    Quellcode

    1. _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    2. NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:kSRCoreDataStoreURL];
    3. NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES};
    4. NSError *error = nil;
    5. NSString *failureReason = @"There was an error creating or loading the application's saved data.";
    6. if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]){...}
    Leicht verwirrt, Mattes
    Diese Seite bleibt aus technischen Gründen unbedruckt.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von MyMattes ()