I am building my project using a master detail VC template with core data.
I am trying to set the values for my attributes in the detail window.
When transitioning from the MasterViewController to the FoodDetailViewController, my NSString attribute works perfectly.
When I add code to add the calorie value attribute (set up as integer 16) my app crashes.
I generated a class file for my entity and the calories property is declared like this:
@property (nonatomic, retain) NSNumber * calories;
This is how I set up the transition.
In MasterViewController.m in prepareForSegue, I set the keyString as such:
foodDetailVC.calorieKeyString = @"calories”;
Then in FoodDetailViewController.h I did:
@property (nonatomic, strong) NSString *calorieKeyString;
in FoodDetailViewController.m I did:
-(void)configureView
{
if (self.managedNutritionValuesObject) {
//refresh content to ensure most up to date data
[self.managedObjectContext refreshObject:self.managedNutritionValuesObject
mergeChanges:YES];
//covert NSNumber values to NSString values
NSString *caloriesString = [NSString stringWithFormat:@"%@",
self.managedNutritionValuesObject.calories];
//set nutrition values in text fields
//these first two lines are for food text field
self.foodNameTextField.text = [self.managedNutritionValuesObject
valueForKey:self.foodNameKeyString];
self.foodNameTextField.clearsOnBeginEditing = YES;
self.caloriesTextField.text = [caloriesString valueForKey:self.calorieKeyString];
self.caloriesTextField.text = caloriesString;
}
}
the crash log says it is crashing on configure view and I get this message:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<__NSCFString 0x8b44e20> valueForUndefinedKey:]: this class is not key value coding-compliant for the key calories.’
Any help would be greatly appreciated, Thanks