CoreData exception/crash using NSInMemoryStoreType and NSExpressionDescription

Number:rdar://12021880 Date Originated:8/2/2012
Status:Open Resolved:
Product:iPhone SDK Product Version:5.1
Classification:Bug Reproducible:Always

I have a simple CoreData-backed iOS project, with a test suite using an NSInMemoryStoreType data store.  When I perform a fetch request which uses an NSExpressionDescription (to calculate an average for a field) I get a crash with -[__NSCFNumber count]: unrecognized selector sent to instance.  When I switch the store type to NSSQLiteStoreType the fetch succeeds as expected.

Steps to Reproduce:

given an otherwise working NSFetchRequest, configure with the following code:

        [fetchRequest setResultType:NSDictionaryResultType];

        NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"duration"];
        NSExpression *avgExpression = [NSExpression expressionForFunction:@"average:" arguments:[NSArray arrayWithObject:keyPathExpression]];

        NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
        [expressionDescription setName:@"averageDuration"];
        [expressionDescription setExpression:avgExpression];
        [expressionDescription setExpressionResultType:NSDoubleAttributeType];

        [fetchRequest setPropertiesToFetch:[NSArray arrayWithObject:expressionDescription]];

NSArray *resultSet = [context executeFetchRequest:fetchRequest error:&error];

Expected Results:

Executing the fetch request should succeed and return a dictionary in the resultSet array, with an NSNumber for the averageDuration key

Actual Results:

An exception/crash with -[__NSCFNumber count]: unrecognized selector sent to instance. Switching to an NSSQLiteStoreType results in the request succeeding as expected.


Had the same issue - thanks for pointing out that is it linked to the use of NSInMemoryStoreType.

I posted a duplicate bug report (rdar://12795203).

2 years later - not fixed

Posted my as: rdar://16644607

By jkirsakmens at April 17, 2014, 9:05 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!