Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am doing a project which involved in Core Data, and I would like to share something with you about it. </p> <p>It is a clear that before you delete or update a record you need to retrieve that record.</p> <p>Use the employee with empId 12345 as an example, </p> <p>a)Delete</p> <pre><code>NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@:@"Employee" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"empId = %d", 12345]]; [request setPredicate:pred]; NSArray *empArray=[self.managedObjectContext executeFetchRequest:request error:nil]; [request release]; if ([empArray count] &gt; 0){ Employee *employee = [empArray objectAtIndex:0]; [self.managedObjectContext deleteObject:employee]; [self.managedObjectContext save:nil]; } </code></pre> <p>b) update</p> <pre><code>NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@:@"Employee" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"empId = %d", 12345]]; [request setPredicate:pred]; NSArray *empArray=[self.managedObjectContext executeFetchRequest:request error:nil]; [request release]; if ([empArray count] &gt; 0){ Employee *employee = [empArray objectAtIndex:0]; employee.empSalary=[NSNumber numberWithInt:45000]; employee.empName=@"John"; employee.empDesignation=@"Analysist"; employee.empExp=@"4 Years"; [self.managedObjectContext save:nil]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload