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?

È stato utile?

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
scroll top