Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting runtime error when doing fast enumeration over an NSArray of entities from Core Data in iOS
    text
    copied!<p>I have an NSArray of Objects of type NSManagedObject that are returned from a fetch result I perform in Core Data. The NSArray contains objects, as I am able to verify this after the query by printing the contents of the NSArray to the console. My problem however is that I am unable to do fast enumeration over this array using objects of the type of entity that I have retrieved from the query. The exact error I am getting at runtime is the following:</p> <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[My_Entity_Name countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xa9f0090' </code></pre> <p>My for loop that I am using doesn't even get to run because it breaks at the for loop condition:</p> <pre><code>for (MyEntityType *entityType in self.entityArray) { ... } </code></pre> <p>The actual fetch command I use to populate the array self.entityArray is:</p> <pre><code>self.entityArray = [[Singleton sharedInstance] retrieveEntities:self.mainEntity.relationshipEntity.relationshipEntityId]; </code></pre> <p>in turn, this is how my retrieveEntity method looks like:</p> <pre><code>- (NSArray *)retrieveEntities:(NSNumber *)relationshipEntityAttributeId { NSManagedObjectContext *context = [[DataEngine sharedInstance] managedObjectContext]; NSError *error; // Create fetch request NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:ENTITY_NAME inManagedObjectContext:context]; [fetchRequest setEntity:entity]; // Create predicate NSPredicate *pred = [NSPredicate predicateWithFormat:@"relationshipEntity.relationshipAttributeId == %@", relationshipEntityAttributeId]; [fetchRequest setPredicate:pred]; NSArray *items = [context executeFetchRequest:fetchRequest error:&amp;error]; if ([items count]&gt;0) { return items[0]; } else { return nil; } } </code></pre> <p>Can anyone see why I am getting the above error?</p> <p>Thanks in advance to all who reply.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload