views:

18

answers:

1

I try count number in (values8 for example) 1 of 100 attributes of Event

And always got that count all number in all property of Event!

 NSFetchRequest *fetchRequests = [[NSFetchRequest alloc] init];
 NSEntityDescription *entit = [NSEntityDescription entityForName:str  inManagedObjectContext:app.managedObjectContext];
 NSDictionary *entityProperties = [entit propertiesByName];
 [fetchRequests setReturnsDistinctResults:YES];
 [fetchRequests setEntity:entit] ;

 [fetchRequests setPropertiesToFetch :[NSArray arrayWithObject:[entityProperties objectForKey:value]]]; 
 NSError *error;
 NSArray *fetchedObject = [app.managedObjectContext executeFetchRequest:fetchRequests error:&error];
 NSManagedObject *fetched ;
 NSManagedObject *fetch ;
    printf("\n%d", [fetchedObject count]);
A: 

You don't have a predicate. As written you code ask for an array containing the value of a specific attribute for every existing instance of the Event entity in the object graph. The count of the array will be the count of all Event instances in the object graph. If you want to find specific Event instances with specific values you need to provide the fetch a predicate.

See the Predicate Programming Guide

If you want to perform operations on the array returned by the fetch see: Collection Operators

TechZen
NSPredicate *predicate = [NSPredicate predicateWithFormat:value];
Andrew H
I thought that setPropertiesToFetch - locate property that i need. NSPredicate error - Unable to parse the format string "values58"'
Andrew H
It will locate the property of each instance of the entity but without a predicate it will return one property value for each instances. E.g. if you have 10 Event objects you get an array with ten property values.
TechZen