Error when populating table view with coredata
<p>I am working with coredata and successfully saved the data in data storage but when I try to output what I stored using table view ,I am not able to do it.</p>

<p>Here the user will enter and click save ..so when he goes back..I want the table to populated with what name he or she has entered.</p>

<p>So I wrote the below code for saving and find data:</p>

<pre><code>- (void) saveData
{
    coredata123AppDelegate *appDelegate = 
    [[UIApplication sharedApplication] delegate];

    NSManagedObjectContext *context = 
    [appDelegate managedObjectContext];
    Contacts *newContact;
    newContact = [NSEntityDescription
                  insertNewObjectForEntityForName:@"Contacts"
                  inManagedObjectContext:context];
    [newContact setValue:name.text forKey:@"name"];
    [newContact setValue:address.text forKey:@"address"];
    [newContact setValue:phone.text forKey:@"phone"];
    name.text = @"";
    address.text = @"";
    phone.text = @"";
    NSError *error;
    [context save:&amp;error];
    status.text = @"Contact saved";    
}

- (void) findContact
{
    coredata123AppDelegate *appDelegate = 
    [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = 
    [appDelegate managedObjectContext];
    NSEntityDescription *entityDesc = 
    [NSEntityDescription entityForName:@"Contacts" 
                inManagedObjectContext:context];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDesc];
    NSPredicate *pred = 
    [NSPredicate predicateWithFormat:@"(name = %@)", 
     name.text];
    [request setPredicate:pred];
    NSManagedObject *matches = nil;
    NSError *error;
    NSArray *objects = [context executeFetchRequest:request 
                                              error:&amp;error];

    for(Contacts *info in objects)
    {
        NSLog(@"Name:%@",info.name);
        NSLog(@"Address:%@",info.address);
    }   
    if ([objects count] == 0) {
        status.text = @"No matches";
    } else {
        matches = [objects objectAtIndex:0];
        address.text = [matches valueForKey:@"address"];
        phone.text = [matches valueForKey:@"phone"];
        status.text = [NSString stringWithFormat:
                       @"%d matches found", [objects count]];
    }
    [request release];


}
</code></pre>

<p>And to populate the table view i have written this code..</p>

<pre><code>- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription 
                                   entityForName:@"Contacts" inManagedObjectContext:context];
    [fetchRequest setEntity:entity];
    NSError *error;
    self.contacts = [context executeFetchRequest:fetchRequest error:&amp;error];

    [fetchRequest release];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    Contacts *info =[contacts objectAtIndex:indexPath.row];
    cell.textLabel.text =info.name;
    cell.detailTextLabel.text=info.address;

    // Configure the cell...

    return cell;
}
</code></pre>
