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

  • SEARCH
  • Home
  • 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 7928201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:40:33+00:00 2026-06-03T19:40:33+00:00

When I insert new object I do with following code: NSManagedObjectContext *context = [appDelegate

  • 0

When I insert new object I do with following code:

NSManagedObjectContext *context = [appDelegate managedObjectContext];

Favorits *favorits = [NSEntityDescription insertNewObjectForEntityForName:@"Favorits" inManagedObjectContext:context];

favorits.title = @"Some title";

NSError *error;                    
if (![context save:&error]) {
    NSLog(@"Whoops");
}

How can I update existing object in core data?

  • 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-06-03T19:40:34+00:00Added an answer on June 3, 2026 at 7:40 pm

    Updating is simple as creating a new one.

    To update a specific object you need to set up a NSFetchRequest. This class is equivalent to a SELECT statetement in SQL language.

    Here a simple example:

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"Favorits" inManagedObjectContext:moc]];
    
    NSError *error = nil;
    NSArray *results = [moc executeFetchRequest:request error:&error];
    
    // error handling code
    

    The array results contains all the managed objects contained within the sqlite file. If you want to grab a specific object (or more objects) you need to use a predicate with that request. For example:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title == %@", @"Some Title"];
    [request setPredicate:predicate]; 
    

    In this case results contains the objects where title is equal to Some Title. Setting a predicate is equal to put the WHERE clause in a SQL statement.

    For further info I suggest you to read the Core Data programming guide and NSFecthRequest class reference.

    • Core Data Programming Guide

    • NSFecthRequest Class Reference

    Hope it helps.

    EDIT (snippet that can be used to update)

    // maybe some check before, to be sure results is not empty
    Favorits* favoritsGrabbed = [results objectAtIndex:0];    
    favoritsGrabbed.title = @"My Title";
    
    // save here the context
    

    or if you are not using a NSManagedObject subclass.

    // maybe some check before, to be sure results is not empty
    NSManagedObject* favoritsGrabbed = [results objectAtIndex:0];
    [favoritsGrabbed setValue:@"My title" forKey:@"title"];
    
    // save here the context
    

    In both cases if you do a save on the context, data will be updated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to insert some data from a GridView to a
Lets assume the following code handling the SaveChanges event of a DataContext void Context_SavingChanges(object
Currently I have The following code: void Page_Load(object sender, System.EventArgs e) { string connectionString
I'm trying to insert a new object into my database. I followed a step-by-step
When I insert data with the following code, I see the exception. What should
The following code generates the primaey key for the new record to be inserted
I'm trying to use the following code to push a new view controller on
Giving the following code: Animal a = new Animal { Name = Rover, Type
I have the following code: List<MyType> myList = new List<MyType>(); // ... add items
The following code shows that I can insert uncompatible type into Map, but when

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.