NSEntityDescription entityForName returns zero

I made some changes to my model (but I don't need migration yet, so I just uninstall the application, built a clean one, etc.)

However, when I run it on the iPhone or in the simulator, I get the following error:

*** The application terminated due to the undetected exception "NSInvalidArgumentException", reason: "executeFetchRequest: error: the query for the selection must have an object."

I set the object as follows:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Document" inManagedObjectContext:managedObjectContext];

My managed objectObjectContext is not null. But I suspect that it does not load the object model correctly or something like that, because if I display objects in the model, the list is empty:

managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
NSLog(@"%d", [[managedObjectModel entities] count]);

How can I make sure the model is loaded?

+3
7

? , .

-[NSManagedObjectModel entities] , .

, -[NSPersistentStore managedObjectModel], , , .

, , . .

+6

. TechZen, , Xcode 3.x, " ", "".

UPDATE: Xcode 4 " " . "Target Membership" .

+6

, , , xcdatamodeld , , , , . (, , ), .

+1

Xcode 4.4.

, Xcode 4.4 datamodel . , .

0

. , , .

:

  • , : NSDictionary * dictionary = [self.managedObjectContext.persistentStoreCoordinator.managedObjectModel entitiesByName]; [ enumerateKeysAndObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^ ( id, id obj, BOOL * stop) {   NSLog (@ "% @=% @", , obj); }];
  • : NSLog (@ " :% d", [[self.managedObjectContext.persistentStoreCoordinator.managedObjectModel entity] count]);
0

:

  • Model.xcdatamodeld ( A),
  • lib
  • 2 static lib ( B)

, B

Model.xcdatamodeld , , .

0

. / (& ):

NSEntityDescription *e = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:testContext];

.., , , , , .

, , , :

NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:testContext];

I would like to tell you why this is fixed - I'm still not sure. I previously tried all the solutions posted on this page. I suspect that this is due to the “opening of several projects”, so if you are in the same situation as me, try manually rewriting the process of loading / receiving datamodel data.

0
source

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


All Articles