Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
I'm getting an exception during a core data migration -

Code:
-[NSSymbolicExpression length]: unrecognized selector sent to instance

Here's the relevant part of the stack trace:

Code:
Exception at stack trace: (
	0   CoreFoundation                      0x00007fff850807b4 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x00007fff824190f3 objc_exception_throw + 45
	2   CoreFoundation                      0x00007fff850da110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
	3   CoreFoundation                      0x00007fff8505291f ___forwarding___ + 751
	4   CoreFoundation                      0x00007fff8504ea68 _CF_forwarding_prep_0 + 232
	5   Foundation                          0x00007fff86b3dd23 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 57
	6   Foundation                          0x00007fff86ba0902 -[NSFunctionExpression expressionValueWithObject:context:] + 530
	7   Foundation                          0x00007fff86ba088d -[NSFunctionExpression expressionValueWithObject:context:] + 413
	8   CoreData                            0x00007fff813b8fc8 -[NSEntityMigrationPolicy createRelationshipsForDestinationInstance:entityMapping:manager:error:] + 1160
	9   CoreData                            0x00007fff813bcce7 -[NSMigrationManager(InternalMethods) _doSecondPassForMapping:error:] + 551
	10  CoreData                            0x00007fff813bbb70 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 2224
	11  CoreData                            0x00007fff813b6ab3 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 147
	12  CoreData                            0x00007fff813b68ca -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 106
	13  CoreData                            0x00007fff813b77cc -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 1116
	14  CoreData                            0x00007fff812f863d -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 1997
	15  AppKit                              0x00007fff841c3101 -[NSPersistentDocument configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:] + 255
	16  Beadia                              0x0000000100004a6d -[BeadiaDocument configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:] + 525

The new model simply has a few extra fields, both transient and non-transient, in existing entities and a couple of new entities. I have a mapping model in place, and now this exception has appeared (the migration has been successful a few times now).

Any ideas as to how I can debug this? I've been through the mapping model and can't see anything wrong, there are no literal values and I've not made any changes. Google finds nothing relevant about this exception.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,706
8,346
A sea of green
An "unrecognized selector" exception is often due to an over-release or under-retain. When that happens, the object-pointer is recycled, the pointer then points to a different class, and the old object-pointer now tries to run a method (e.g. length) on an object whose class (e.g. NSSymbolicExpression) doesn't have that method. This wouldn't be expected if you're using ARC, but since you didn't say, I'll guess you're not.

Another cause of "unrecognized selector" is a mistake in the presumed class of an object when KVC is being used. Since valueForKeyPath: is in the stack trace, and that's a KVC method, that's where you should probably start. You may be making an assumption somewhere that the class should be X when it's really Y. I don't know what X is, but it's something with a length method. Y is clearly NSSymbolicExpression.

And google finds quite a lot on "unrecognized selector sent to instance", and they seem quite relevant to me. Top result:
http://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance
which mentions memory management issues.
 

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
Thanks, I think it's memory management too (I'm using GC :( ). I've narrowed the issue down to one specific entity - I set up an NSEntityMigrationPolicy subclass which outputs debug information in the createRelationshipsForDestinationInstance:entityMapping:manager:error: method which helps to show what's going on.
 

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
I finally found this, I think. I have an entity with a relationship called size, which is a Core Data reserved word. When XCode generated a mapping model it didn't prefix the size with # in the same way it does for a non-relationship attribute. I just added the # and everything seems okay.

It's only taken DAYS to find this... :rolleyes:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.