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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:57:00+00:00 2026-06-12T12:57:00+00:00

I am trying to update my local database when app gets response from the

  • 0

I am trying to update my local database when app gets response from the web server. When app gets the update from web server, I fetch the data from the local database by matching the id with the response and get one row and perform update code but local database does not get updated and also does not give an error.
What should be the solution???

-(void)checkID:(NSMutableDictionary *)dict
{
    NSDictionary *dictEvent = [dict objectForKey:@"Event"];

    NSManagedObjectContext *context = [self managedObjectContext];

    NSManagedObject *selectedManagedObject = nil;

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Events" inManagedObjectContext:context];
    NSSortDescriptor *sortDescObj = [[NSSortDescriptor alloc] initWithKey:@"event_id" ascending:YES];
    NSError *error = nil;

    NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"user_id=%@ and event_id=%@",[NSNumber numberWithInt:[[dictEvent valueForKey:@"user_id"] intValue]],[NSNumber numberWithInt:[[dictEvent valueForKey:@"id"] intValue]]]];

    NSLog(@"Predicate = %@",predicate);

    NSArray *arrSortDescriptors = [NSArray arrayWithObject:sortDescObj];
    [fetchRequest setSortDescriptors:arrSortDescriptors];

    [fetchRequest setEntity:entity];
    [fetchRequest setReturnsDistinctResults:YES];

    [fetchRequest setPredicate:predicate];

    NSArray *arrResult = [context executeFetchRequest:fetchRequest error:&error];

    if ([arrResult count]>0) 
    {                
            NSArray *arrKey = [dictEvent allKeys];
            NSArray *arrValue = [dictEvent allValues];

           NSLog(@"ArrKey : %@\nArrValue : %@",arrKey,arrValue);

           selectedManagedObject = [arrResult objectAtIndex:0];


           for(int i = 0; i < [arrKey count] ; i++) 
           {
               NSLog(@"selectedMng :- %@",selectedManagedObject);
               NSLog(@"KEY: %@\t: %@",[arrKey objectAtIndex:i],[arrValue objectAtIndex:i]);
               if ([[arrKey objectAtIndex:i]isEqualToString:@"id"]) 
               {
                  [selectedManagedObject setValue:[arrValue objectAtIndex:i] forKey:@"event_id"]; 
               }
               else if([[arrKey objectAtIndex:i]isEqualToString:@"invited_status"])
               {
                   [selectedManagedObject setValue:[arrValue objectAtIndex:i] forKey:@"invite_status"];
               }
               else
               {
                   [selectedManagedObject setValue:[arrValue objectAtIndex:i] forKey:[arrKey objectAtIndex:i]];
               }

           }
           if (! [selectedManagedObject.managedObjectContext save:&error])  
           {
               NSLog(@"updateEntityIntoDataBaseNamed - Error :: %@", [error localizedDescription]);
           }
      // }

    }
}
  • 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-12T12:57:02+00:00Added an answer on June 12, 2026 at 12:57 pm

    Besides modifying your predicate as suggested by @Martin

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_id=%@ && event_id=%@",
        [NSNumber numberWithInt:[[dictEvent valueForKey:@"user_id"] intValue]],
        [NSNumber numberWithInt:[[dictEvent valueForKey:@"id"] intValue]]
    ];
    

    note that in two cases, you are updating your object using non matching keys: this happens for id and event_id, and for invited_status and invite_status.

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

Sidebar

Related Questions

I am trying to update some local access databases from a web database. When
I'm trying to update a local Access 2010 table by pulling data from a
When trying to update a subversion working copy from Netbeans, I get the following
I'm trying to update a legacy app that does all its data storage in
We have a local server with an access database which feeds data to clients
I'm trying to use a stored procedure to query some data from my database,
Trying pull the database from Hekoku to local but failed. heroku db:pull postgres://root:@localhost/db_name Admittedly,
I'm trying to develop a system that will allow users to update local, offline
I am trying to write a simple JavaScript page timer for a web app.
I created a new Rails API app. I am trying to create the database

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.