Come fare un NSFetchRequest che chiede per gli oggetti che hanno un cognome specifico?
-
20-09-2019 - |
Domanda
Per esempio, ho un modello a oggetti gestito con un'entità denominata "Amici", e un amico ha un firstName. Voglio ottenere tutti gli amici in cui il firstName è uguale a "George". Come posso fare?
Soluzione
Utilizzare questa:
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Friends" inManagedObjectContext:context];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
[request setPredicate:[NSPredicate predicateWithFormat:@"firstName == 'George'"]];
NSError *error = nil;
NSArray *array = [context executeFetchRequest:request error:&error];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow