NSUrl problem


#1

I run those code in iOS device good, but It have error in simulator,
In code, NSString path — /Users/apple/Library/Application Support/iPhone Simulator/6.1/Applications/8F9F4D7A-9061-49EB-AD2B-4D3C6F8B217D/Documents/store.data
NSUrl storeURL ----- [file://localhost/Users/apple/Library/Ap … store.data](file://localhost/Users/apple/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/8F9F4D7A-9061-49EB-AD2B-4D3C6F8B217D/Documents/store.data)
Then there is exception: 2013-04-05 11:30:00.747 [68558:c07] *** Terminating app due to uncaught exception ‘Open failed’, reason: ‘Reason:The operation couldn’t be completed. (Cocoa error 134100.)’
*** First throw call stack:
(0x15d1012 0x13f6e7e 0x15d0deb 0x4a02 0x4768 0x2d42 0x51f548 0x522224 0x3e6952 0x3e62dc 0x2c25 0x41c1c7 0x41c232 0x56a05b 0x24a8 0x1fb1 0x338157 0x338747 0x33994b 0x34acb5 0x34bbeb 0x33d698 0x241edf9 0x241ead0 0x1546bf5 0x1546962 0x1577bb6 0x1576f44 0x1576e1b 0x33917a 0x33affc 0x1ded 0x1d15)
libc++abi.dylib: terminate called throwing an exception

Thanks

BNRItemStore.m

[code]-(id)init
{
self=[super init];
if (self) {

    /*NSString *path=[self itemArchivePath];
    allItems=[NSKeyedUnarchiver unarchiveObjectWithFile:path];
    if (!allItems) {
        allItems=[[NSMutableArray alloc] init];*/
    
model=[NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator *psc=[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
    NSString *path=[self itemArchivePath];
    NSURL *storeURL=[NSURL fileURLWithPath:path];
    NSError *error=nil;
    if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        [NSException raise:@"Open failed" format:@"Reason:%@",[error localizedDescription]];
    }
    context=[[NSManagedObjectContext alloc] init];
    [context setPersistentStoreCoordinator:psc];
    [context setUndoManager:nil];
    [self loadAllItems];
    }
return self;

}
/code]


#2

That’s an exception which you are throwing in your code and which you probably are not catching.

...
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
     [NSException raise:@"Open failed" format:@"Reason:%@",[error localizedDescription]];
}
...

Try catching the exception and presenting the reason to the user rather than let the application terminate.

PS: When posting code, please include it between Code tags to make it easier for others to view your code.


#3

I solved the problem after I googled this:http://stackoverflow.com/questions/5517129/core-data-cocoa-error-134100
I deleted old store.data, the code run well in simulator. the article above link explain that
new managed object model try to use old version store.data.