Trying to update an fetched object and getting 'unrecognized selector sent to instance' error whenever I try and set any property on the object, here is my code:
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSEntityDescription *entities = [NSEntityDescription entityForName:@"PurchaseOrderItem" inManagedObjectContext:managedObjectContext];
[request setEntity:entities];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ItemSKU=%@",collectionItem.ItemSKU];
[request setPredicate:predicate];
NSArray *results= [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if ([results count]==0) {
/* add another purchase order item */
PurchaseOrderItem *newPOItem = (PurchaseOrderItem*) [NSEntityDescription insertNewObjectForEntityForName:@"PurchaseOrderItem" inManagedObjectContext:managedObjectContext];
[newPOItem setProductName:productName.text];
[newPOItem setPrice:price];
[newPOItem setQuantity:qty];
[newPOItem setItemSKU:ItemSKU];
[newPOItem setSubTotal:itemSubTotal];
}else {
/* update item */
PurchaseOrderItem *updateObject = (PurchaseOrderItem*)[results objectAtIndex:0];
[updateObject setSubTotal:itemSubTotal];
[updateObject setQuantity:qty];
}
EDIT: here is the exact error:
2010-07-12 22:07:37.920 RCoreData[46733:207] *** -[PurchaseOrder setSubTotal:]: unrecognized selector sent to instance 0x587b270
2010-07-12 22:07:37.921 RCoreData[46733:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[PurchaseOrder setSubTotal:]: unrecognized selector sent to instance 0x587b270'
2010-07-12 22:07:37.921 RCoreData[46733:207] Stack: (
46504016,
47661868,
46512731,
45975158,
45971954,
209089,
3382510,
3879998,
3889344,
3884141,
3509736,
3401283,
3432920,
53940604,
45783196,
45779112,
53934237,
53934434,
3425138,
10940,
10794
)
terminate called after throwing an instance of 'NSException'
Note: Adding the item is working great, it is the update part that is throwing the error:
/* update item */
PurchaseOrderItem *updateObject = (PurchaseOrderItem*)[results objectAtIndex:0];
[updateObject setSubTotal:itemSubTotal];
[updateObject setQuantity:qty];