PopUp
PopUp

Reputation: 171

Saving UILabel results into CoreData

I have a picker on a ViewController and the results print out on a label. I am having a problem saving these results into CoreData, getting an error code

"[<__NSCFConstantString 0xf488> valueForUndefinedKey:]: this class is not key value coding-compliant for the key attribute.'.

Here is the code that prints out the label:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    mlabel.text= [arrayNo objectAtIndex:row];
}

Here is the code that saves the label results to core data:

- (IBAction)editSaveButtonPressed:(id)sender
{

    if (!currentCategory)
        self.currentCategory = (Entity *)[NSEntityDescription insertNewObjectForEntityForName:@"Entity" inManagedObjectContext:self.managedObjectContext];  

    [self.currentCategory setAttribute:[mlabel text]];  //This is the line causing the error

    NSError *error;

    if (![self.managedObjectContext save:&error])
       NSLog(@"Failed to add new category with error: %@", [error domain]); 

    [self.navigationController popViewControllerAnimated:YES];
}

Why is this causing an error? Thank you in advance for your input.

Upvotes: 0

Views: 324

Answers (1)

jlstrecker
jlstrecker

Reputation: 5033

Looks like there is no attribute property (thus setAttribute) defined on Entity.

You might want to check out this tutorial on Core Data: http://www.raywenderlich.com/934/core-data-tutorial-getting-started

Upvotes: 1

Related Questions