Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7001541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:49:00+00:00 2026-05-27T20:49:00+00:00

I am learning the core data How to delete and update the data using

  • 0

I am learning the core data
How to delete and update the data using core data. I have worked on upload and fetch. I need to write the methods for delete and update. Please tell me how to update and delete a recode using core data.

Below I have written code for upload and fetch data from table using core data.

-(void)uploadData
{
    Employee *empObj=(Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];


    empObj.empId=[NSNumber numberWithInt:12345];
    empObj.empSalary=[NSNumber numberWithInt:25000];

    empObj.empName=@"Venu";
    empObj.empDesignation=@"Programmer";
    empObj.empExp=@"2 Years";

    if ([self.managedObjectContext hasChanges] )
    {
        [self.managedObjectContext save:nil];
    }

}
-(void)fetchData
{
    NSEntityDescription *empEntity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext];

    // Setup the fetch request
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entity];

    NSArray *fatherArray=[self.managedObjectContext executeFetchRequest:request error:nil];

    [request setEntity:empEntity];

    NSArray *empArray=[self.managedObjectContext executeFetchRequest:request error:nil];

    for (int i=0; i<[empArray count]; i++) 
    {
        printf("\n=================================Recored== %d==================================== ",i);

        Employee *empObj=[empArray objectAtIndex:i];
        printf("\n obj.empName========= %s",[empObj.empName UTF8String]);
        printf("\n obj.empDesignation========= %s",[empObj.empDesignation UTF8String]);
        printf("\n obj.empExp========= %s",[empObj.empExp UTF8String]);
        printf("\n obj.empId========= %d",[empObj.empId intValue]);
        printf("\n obj.empSalary========= %d",[empObj.empSalary intValue]);
        printf("\n============================================================================= ");

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:49:01+00:00Added an answer on May 27, 2026 at 8:49 pm

    I am doing a project which involved in Core Data, and I would
    like to share something with you about it.

    It is a clear that before you delete or update a record you need
    to retrieve that record.

    Use the employee with empId 12345 as an example,

    a)Delete

    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] > 0){
        Employee *employee = [empArray objectAtIndex:0];
        [self.managedObjectContext deleteObject:employee];
        [self.managedObjectContext save:nil];
    }
    

    b) update

    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] > 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];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning to use Core Data. I have created a data model etc
I am using Apple's CoreDataBooks sample project as a learning aid for core data.
I am learning Core Data so I was confused about the following. I need
I am just learning Core Data on iPhone and the tutorial I am following
I am learning core Java and I have one question, Which is the first
I'm currently learning to use Core Data on iOS , in my test application
I'm learning Core Data with the help of the book. There is a code:
I've just started learning to use Core Data. On my first attempt to add
I've been learning how to use Core Data in xcode for a couple of
i´m currently learning Core Data. Core Data is great but i can not explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.