How to make requests to Core Data to get only one attribute?

0

I only need to get an attribute from a single row of the table:

 name  | id   | idade  | aprov|repro| sala | 
_______|______|________|______|_____|______| 
John   |  32  |    15  |   A  |     | 155  | 

Following the table above, it would be the idade field containing the 15 element.

How can I do this using Core Data?

In case this app is for iOS.

    
asked by anonymous 28.10.2014 / 16:12

1 answer

1

To get only the age column you define the setPropertiesToFetch: method of your NSFetchRequest object, something like this:

[request setPropertiesToFetch:[NSArray arrayWithObjects:@"idade", nil]];

And to make the filter, a NSPredicate :

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id == %d", 32];
[request setPredicate:predicate];

And so it does the rest of your request that will return a single object, according to id .

    
28.10.2014 / 16:24