Crash on accessing NSManagedObject property after migratePersistentStore: to another URL on OS X 10.9 Mavericks

StackOverflow https://stackoverflow.com/questions/21890088

Frage

I have a code that works fine on OS X 10.9 before I migrate the persistent store to another URL. After migration app crashes when I try to execute fetch request and sort by an existing property of fetched items. On OS X 10.8 it works fine before and after migration. Any help is highly appreciated.

Here's the store migration, nothing fancy:

    BOOL success = [storeCoordinator migratePersistentStore:store toURL:[NSURL fileURLWithPath:newPath] options:nil withType:NSSQLiteStoreType error:&error];

Migration proceeds successfully, without errors. Here's the crashing code (which worked fine before migration):

    NSManagedObjectContext *moc = [appDelegate managedObjectContext];

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:moc];
    [request setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == nil", @"parent"];
    [request setPredicate:predicate];

    // SORTING BY "sortOrder" PROPERTY CRASHES THE APP
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 
    [request setSortDescriptors:sortDescriptors];

    NSError *error; 
    NSMutableArray *fetchResults = [moc executeFetchRequest:request error:&error];

Crash details:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x60)

0x00007fff89a64ad0 in _propertyAtIndexForEntityDescription ()
0x00007fff89a631dd in snapshot_get_value_as_object ()
0x00007fff931ea49f in -[NSObject(NSKeyValueCoding) valueForKeyPath:] ()
0x00007fff931e904c in _sortedObjectsUsingDescriptors ()
0x00007fff931e8e69 in -[NSArray(NSKeyValueSorting) sortedArrayUsingDescriptors:] ()
0x00007fff89a459f0 in -[NSManagedObjectContext executeFetchRequest:error:] ()

Update [2] Thanks to Tom Harrington's question, I was able to narrow the issue down to this:

Update [3] It appears there's a number of specific keys causing this crash. Out of dozen of different properties of the fetched items, accessing 3 particular properties of type NSDate and 'double' cause the app to crash. All of them has some meaningful value.

There're other properties of type NSString, Boolean, Integer 16, Integer 32 and Binary Data. Some of them are nil, some set to default value, some has some other value. They can be accessed without any error. AND there's one NSDate property without any value including default and it can be accessed without problems also.

Why does it crash? Before migrating store to another URL I can successfully access these properties.

War es hilfreich?

Lösung

Seems to be a problem with a specific project created a while ago. Probably during these years something got messed in project files and settings.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top