views:

230

answers:

1

I'm relatively well versed in CoreData and have been using it for several years with little or no difficulty. All of a sudden I'm now dumbfounded by an error. For the life of me, I can't figure out why

insertNewObjectForEntityForName:inManagedObjectContext:

is all of a sudden returning some sort of strange instance of NSNumber. GDB says the returned object is of the correct custom subclass of NSManagedObject, but when I go to print a description of the NSManagedObject itself, I get the following error:

*** -[NSCFNumber objectID]: unrecognized selector sent to instance 0x3f26f50

What's even stranger, is that I'm able to set some relationships and attributes using setValue:forKey: and all is good. But when I try to set once specific relationship, I get this error:

*** -[NSCFNumber entity]: unrecognized selector sent to instance 0x3f26f50

Has anyone ever encountered anything like this before? I've tried clean all targets, restarting everything, even changing the model to the relationship in question is a to-one instead of a to-many. Nothing makes any difference.

+1  A: 

I've encountered the "unrecognized selector sent to instance 0x..." error before in a situation where the object I expect to be at the memory address "pointer" has been replaced by something else. Take this situation:

NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];
NSString *someString = [NSString stringWithString:@"some string"]; // autoreleased object returned

[pool drain];
[pool release];

/*
some other code executes
*/

// since the string behind the someString variable has been autoreleased at this point, the memory that someString points to may be occupied by some other data type.  the following may through an EXC_BAD_ACCESS error, or it may try and execute the selector on whatever is occupying that memory space
int stringLength = [someString length];

This example is painfully straightforward and my semantics may be a bit off here, but could it be possible that this is what is happening in your case in a more convoluted way? Maybe try:

[[NSEntityDescription insertNewObjectForEntityForName:@"entityName" inManagedObjectContext:managedObjectContext] retain]

and see what happens?

jtrim