Copy existing xcdatamodel into a new project - Can't find model for source store

1.5k views Asked by At

When copying a xcdatamodel to an existing project, the app hangs with the error:

Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x1894f60 {URL=file://localhost/var/mobile/Applications/15214BCA-379F-4A2D-BE40-80F0CC25B50B/Documents/History.sqlite, metadata=<CFBasicHash 0x5b7880 [0x3f3c3630]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x5b79a0 [0x3f3c3630]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x5b7a80 [0x3f3c3630]>{type = immutable, count = 0, values = ()}
    4 : <CFString 0x5b79d0 [0x3f3c3630]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x5b7c00 [0x3f3c3630]>{value = +386, type = kCFNumberSInt64Type}
    6 : <CFString 0x5b7a00 [0x3f3c3630]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x5b7aa0 [0x3f3c3630]>{type = immutable dict, count = 0,
entries =>
}

    7 : <CFString 0x3eb4cf40 [0x3f3c3630]>{contents = "NSStoreUUID"} = <CFString 0x5b7d10 [0x3f3c3630]>{contents = "6FED3F04-493F-4A5B-9423-05475B6F3E0B"}
    8 : <CFString 0x3eb4cde0 [0x3f3c3630]>{contents = "NSStoreType"} = <CFString 0x3eb4cdf0 [0x3f3c3630]>{contents = "SQLite"}
    9 : <CFString 0x5b7a30 [0x3f3c3630]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x561a40 [0x3f3c3630]>{contents = "2"}
    10 : <CFString 0x5b7a50 [0x3f3c3630]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x182b780 [0x3f3c3630]>{value = +3, type = kCFNumberSInt32Type}
}
, reason=Can't find model for source store}, {
    URL = "file://localhost/var/mobile/Applications/15214BCA-379F-4A2D-BE40-80F0CC25B50B/Documents/History.sqlite";
    metadata =     {
        NSPersistenceFrameworkVersion = 386;
        NSStoreModelVersionHashes =         {
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
        );
        NSStoreType = SQLite;
        NSStoreUUID = "6FED3F04-493F-4A5B-9423-05475B6F3E0B";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "Can't find model for source store";
}

The model was taken from another project with the same classes and loaded with the options:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
1

There are 1 answers

0
Egdod On

I don't know if you've figured this out, but your problem may lie in this method from your program's AppDelagate.m:

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel_ != nil) {
        return managedObjectModel_;
    }
    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"DATABASENAME" ofType:@"momd"];
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
    managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
    return managedObjectModel_;
}

where 'DATABASENAME' should be the name of your .xcdatamodel file.