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 6685659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:04:56+00:00 2026-05-26T05:04:56+00:00

If NSFetchRequest is the Core Data equivalent of an SQL query containing SELECT ,

  • 0

If NSFetchRequest is the Core Data equivalent of an SQL query containing SELECT, is there a Core Data equivalent of the SQL command UPDATE?

Or in other words, if I want to change values on a Core Data set, is there a way around iterating over the results of an NSFetchRequest?

In case you’re answering with ‘no’, I’d very much appreciate some kind of reference documentation. Cheers!

EDIT: By ‘iteration’ I mean that I know how to for-loop over the entities and changes values:

NSArray *results = [context executeFetchRequest:...];
for (NSManagedObject *object in results) {
    object.value = anotherValue;
}

But if they’re all getting the same value on the same property, I’d just like to call something like [context executeChangesOnFetchRequest:...]. Of course this method does not exist, but maybe there is a more elegant/concise way than the for-loop.

  • 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-26T05:04:57+00:00Added an answer on May 26, 2026 at 5:04 am

    Well, no. If you want changes to be made on the object context in which the Core Data objects reside, you must set the respective properties on said objects and then commit the changes on that object context. Core Data will handle all the optimizations for you.

    If you’re simply looking for a way to avoid a for loop to update properties on objects in the result set, you can try using makeObjectsPerformSelector:withObject:.

    NSFetchRequest *req = ...;
    NSError *error = nil;
    NSArray *results = [self.managedObjectContext executeFetchRequest:req error:&error];
    if(error != nil) {
      //oops.
    } else {
       //avoid the loop:
       [results makeObjectsPerformSelector:@selector(setSomeProperty:) withObject:someValue];
    
       if(![self.managedObjectContext save:nil]) {
          //error during save
       }
    }
    

    For the adventurous, you can try adding a category on NSManagedObjectContext:

    @interface NSManagedObjectContext (JRAdditions)
    
    - (BOOL) executeChanges:(NSDictionary *) changes 
           withFetchRequest:(NSFetchRequest *) request
                      error:(NSError **) error;
    @end
    
    @implementation NSManagedObjectContext (JRAdditions)
    
    - (BOOL) executeChanges:(NSDictionary *) changes 
           withFetchRequest:(NSFetchRequest *) request
                      error:(NSError **) error {
    
       NSArray *results = [self executeFetchRequest:request error:error];
       if(*error || ![results count]) return NO;
    
       [results makeObjectsPerformSelector:@selector(setValuesForKeysWithDictionary:)
                                withObject:changes];
       return [self save:error];
    }
    
    @end
    

    You could then call this like so:

    NSDictionary *changes = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
    NSFetchRequest *request = ...;
    NSError *error = nil;
    
    if([self.managedObjectContext executeChanges:changes withFetchRequest:request error:&error]) {
       //done.
    } else {
       //error.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in core data , I search using fetchRequest and predicate like the following NSFetchRequest
I want to retrieve data from core data (sqlite database) according to primary key.
Been searching high and low for this: In Core Data, is there a way
I have a NSFetchRequest to search of core data entities. It finds them fine,
I'm learning Core Data with the help of the book. There is a code:
I want to have the equivalent of two completely unrelated tables in my database,
Using Core Data w/a sqlite store on iPhone.... I've got a bunch of comic
this is my core data model: I'm trying to get all LanguageEntries from a
I struggle with Core Data on the iPhone about the following: I have a
I have a Core Data based mac application that is working perfectly well until

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.