Core Data simple get and update
===

i have a Core Data file with
Categories entity, which have 2 attributes - id and name.

Can someone provide me with a method to get values from those 2 attributes, and to update them. I've tried and failed.

Here is my current code:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addCategory:)];
        self.navigationItem.rightBarButtonItem = addButtonItem;
        
    }
    
    -(IBAction)addCategory:(id)sender
    {
        UIAlertView *addCategoryAlertView = [[UIAlertView alloc] initWithTitle:@"Add Category" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
        addCategoryAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
        self.textField = [addCategoryAlertView textFieldAtIndex:0];
        self.textField.placeholder = @"Enter category name";
        [addCategoryAlertView show];
    }

and in the UIAlertView Delegate method

 

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

I must add values to those categories.

Here is how i've done it now:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        
        if (buttonIndex == kAddCategoryButtonIndex) {
            AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
            NSManagedObjectContext *context = [appDelegate managedObjectContext];
            NSError *error;
            
            //NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
            NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"Categories" inManagedObjectContext:context];
            //[fetchRequest setEntity:entity];
            [entity setValue:self.textField.text forKey:@"name"];
            NSLog(@"%@",[entity valueForKey:@"name"]);
            [context save:&error];
        }
    }


And I think it works, but i can't get values from these 2 attributes.

If someone can help me, it's going to be great. Thanks.