Sto provando a recuperare un singolo oggetto dal mio database principale, tuttavia continua a restituire null. Il mio metodo si basa su un altro metodo che restituisce ogni valore dall'oggetto coredata a cui sto accedendo.Come recuperare un singolo oggetto da Coredata usando un predicato
Non l'ho mai provato prima e ho provato a leggere i documenti di mele ma non ha proprio senso ... questo è il mio metodo sembra
- (NSMutableArray *)readSelectedInstall:(NSString *)projIDString {
NSManagedObjectContext *context = [self managedObjectContext];
if (context == nil) {
NSLog(@"Nil");
}
else {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"InstallProject" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ProjID==%@", projIDString];
[fetchRequest setPredicate:predicate];
NSError *error;
NSMutableArray *installProjectDictionaryArray = [[NSMutableArray alloc] init];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (InstallProject *installProj in fetchedObjects) {
NSMutableDictionary *tempInstallProjectDictionaryArray = [[ NSMutableDictionary alloc] init];
[tempInstallProjectDictionaryArray setObject:installProj.companyName forKey:@"CompanyName"];
[tempInstallProjectDictionaryArray setObject:installProj.projNo forKey:@"ProjNo"];
[tempInstallProjectDictionaryArray setObject:installProj.projID forKey:@"ProjID"];
[installProjectDictionaryArray addObject:tempInstallProjectDictionaryArray];
}
return installProjectDictionaryArray;
}
return nil;
}
alcun aiuto me sempre per restituire un singolo elemento questo è projID corrisponde al projIDString sarebbe molto apprezzato.
è 'contesto == quelle negative ? Oppure 'executeFetchRequest' restituisce' nil'? In quest'ultimo caso, qual è il valore di 'error'? –
risulta che non stavo assegnando la mia classe CoredataManagins .. L'ho fatto ora e sto ricevendo un errore. "Terminazione dell'app a causa dell'eccezione non rilevata 'NSInvalidArgumentException', motivo: 'generazione SQL non implementata per predicato: (ANY ProjID CONTAINS [cd]" 10000085 ")'" – HurkNburkS
"ANY ProjID CONTAINS [cd] ..." non è il predicato che hai mostrato nella tua domanda ... –