Bad_APPZ
Bad_APPZ

Reputation: 432

Using core data with and with out a nsfetchedResultsController

In core data, you initially add objects/set their attributes values using:

-(IBAction)save{

if (self.managedObjectContext == nil)
{
    self.managedObjectContext = [(RootAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

    Frame *f = [NSEntityDescription insertNewObjectForEntityForName:@"Frame" inManagedObjectContext:self.managedObjectContext];

        f.typeLabel = self.textFieldtext.text;

    [self dismissViewControllerAnimated:YES completion:nil];

    NSError *error;

    if (![self.managedObjectContext save:&error]) {
        NSLog(@"Error");
    }
}

And you would typically edit the values using:

-(IBAction)save{
[self.f setValue:self.newTextfield.text forKey:@"typeLabel"];

[self dismissViewControllerAnimated:YES completion:nil];
NSError *error;
if (![self.managedObjectContext save:&error]) {
        //Handle Error
}

}

It's obviously a bit different using A NSFetchedResultsController

I guess my question would be, how can I set properties and edit them using a NSFetchedResultsController?

Upvotes: 0

Views: 51

Answers (1)

jrturton
jrturton

Reputation: 119292

A fetched results controller acts as a link between a fetch request and a table view. The useful part is that if you make any changes to the managed object context that would affect the results of the fetch request, the FRC automatically picks up on these and sends various delegate methods which you can tie in to your table view datasource code to keep the table up to date. See "Implementing the Table View Datasource Methods" here.

Your code above isn't really relevant to this, unless it is contained within a modal view controller that is called from a table view displaying the results of a fetch request, and is used for adding new items. In that case, the code above would be identical, but when you returned to the table view, it would already contain your new data.

Upvotes: 2

Related Questions