InsertNewObjectForEntityForName: inManagedObjectContext: returns an NSNumber error?

I am pretty good at CoreData and have been using it for some years with little or no difficulty. Suddenly, I am now stunned by the mistake. For my life I can’t understand why

insertNewObjectForEntityForName:inManagedObjectContext: 

suddenly some strange instance of NSNumber returns. GDB says the returned object has the correct user subclass NSManagedObject, but when I go to print a description of NSManagedObject itself, I get the following error:

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

What's even weirder is that I can set some relationships and attributes using setValue: forKey: and all is well. But when I try to establish a specific relationship, I get this error:

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

Has anyone ever encountered anything similar before? I tried to clear all goals, reset everything, even changing the model to the relationships in question is one thing, not many. Nothing matters.

+4
source share
1 answer

I ran into the error "unrecognized selector sent to instance 0x ..." before in a situation where the object that I expect to be with the address "pointer" has been replaced with 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 simple, and my semantics may be a little from here, but is it possible that this is what happens in your case in a more complicated way? Perhaps try:

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

and see what happens?

+1
source

Source: https://habr.com/ru/post/1308391/


All Articles