How to configure predicate to return only 2 columns?

4

Scenery:

Do a query using CoreData looking for records with a city and state, and return only the 'name' and 'address' columns of the location.

I'm currently using the following query:

// Array to be returned

NSMutableArray* arrayRegistrosFiltrados = [[NSMutableArray alloc] init];
NSManagedObjectContext * context = [self managedObjectContext];

NSError* error;

'// Instancia objeto que irá fazer a requisiçao
NSFetchRequest* requisicao = [[NSFetchRequest alloc]initWithEntityName:entidadeEstacionamento];
NSPredicate* argumentosBusca = [NSPredicate predicateWithFormat:@"estado==%@ AND cidade==%@",estado,cidade];

[requisicao setPredicate:argumentosBusca];

NSArray*registrosTemp = [context executeFetchRequest:requisicao error:&error];'

But this way returns all the columns of the records found.

    
asked by anonymous 11.10.2015 / 16:45

1 answer

3

The class NSFetchRequest has a property called propertiesToFetch .

You can use it as follows:

...

[requisicao setPredicate:argumentosBusca];
[requisicao setPropertiesToFetch:[NSArray arrayWithObjects:@"nome", @"endereco", nil];

...
    
15.10.2015 / 21:23