I am trying to save some data to CoreData but i get the error:
Restaurant Manager[5971:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ProdusComandat setIdProdus:]: unrecognized selector sent to instance 0x90b8270'
Can someone tell me why?
SessionController* sessionController = [[SessionController alloc]init];
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"ComenziActive"];// baza de date
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"numeClient == %@",sessionController.getSessionUsername]];
NSError *err;
NSUInteger count = [self.managedObjectContext countForFetchRequest:fetchRequest error:&err];
NSArray *listaElementeBD = [[NSArray alloc]init];
if(count <= 0)
{
NSEntityDescription *entitydesc;
entitydesc = [NSEntityDescription entityForName:@"ComenziActive" inManagedObjectContext:self.managedObjectContext];
ComenziActive *comanda = [NSEntityDescription insertNewObjectForEntityForName:@"ComenziActive" inManagedObjectContext:self.managedObjectContext];
[comanda setValue:sessionController.getSessionUsername forKey:@"numeClient"];
ProdusComandat * produsComandat = [[ProdusComandat alloc]init];
produsComandat.idProdus = [[[(Produs*)produsdb objectID] URIRepresentation] absoluteString];
produsComandat.cantitateComandata = [NSNumber numberWithInteger:[self.cantitateTextField.text integerValue]];
[comanda addProduseComandateObject:produsComandat];
}
else
{
NSError *error;
listaElementeBD = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
ComenziActive *comanda = [listaElementeBD objectAtIndex: 0];
NSArray *produse = comanda.produseComandate.allObjects;
BOOL found =NO;
for(int i=0;i<[produse count];i++)
{
ProdusComandat *p =[[ProdusComandat alloc]init];
p= produse[i];
if ([p.idProdus isEqualToString:[[[(Produs*)produsdb objectID] URIRepresentation] absoluteString]]) {
p.cantitateComandata = [NSNumber numberWithInteger:[p.cantitateComandata integerValue] + [self.cantitateTextField.text integerValue]];
found = YES;
break;
}
}
if (!found) {
ProdusComandat * produsComandat = [[ProdusComandat alloc]init];
produsComandat.idProdus = [[[(Produs*)produsdb objectID] URIRepresentation] absoluteString];
produsComandat.cantitateComandata = [NSNumber numberWithInteger:[self.cantitateTextField.text integerValue]];
[comanda addProduseComandateObject:produsComandat];
}
NSLog(@"============================");
NSLog(@"%@", comanda.produseComandate );
}
NSError *error;
[self.managedObjectContext save:&error];
What I am trying to do is get the data from CoreData entity Produs and copy it's objectID to the entity ProduseComandate that has this relationship ComenziActive<----->>ProduseComandate(relationship one-to-many) if that objectID doesn't exist in the table, but if it does exist, I want to add to the value cantiate some value that I take from the TextField.
idProdus
defined? – Wain