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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:08:52+00:00 2026-06-06T18:08:52+00:00

I am using core data to store some details. But when I run my

  • 0

I am using core data to store some details. But when I run my app for the second time the contents in the entity gets doubled. and this continues each time I run my app. I tried to delete the objects before I add like this question Core Data: Quickest way to delete all instances of an entity but then the deletion works successfully not the addition part and hence am getting quit in the code (from some other part from where I am accessing the Data base)

I used the below code

-(void)synDBFavSpecies:(NSString *)speciesName:(NSString *)speciesId:(NSString *)Imagename
{ 
    NSManagedObjectContext *context=app.managedObjectContext; 
    NSError *err;

    NSFetchRequest *request1=[[NSFetchRequest alloc]init];
    NSEntityDescription *entity1=[NSEntityDescription entityForName:@"FavoriteSpecies" inManagedObjectContext:context];
    [request1 setEntity:entity1];
    NSArray *result1=[context executeFetchRequest:request1 error:&err];
    NSManagedObject *ph1;
    for(ph1 in result1 )
    {
        [context deleteObject:ph1];
        NSString *sid= [ph1 valueForKey:@"ID"]; 
        NSLog(@"Sp.ID:%@",sid);

        if(sid)
        {

            [context deleteObject:ph1];
            if(![context save:&err])
            {
                NSLog(@"error");
            }
        }
    }

    NSManagedObject *SetDB=[NSEntityDescription insertNewObjectForEntityForName:@"FavoriteSpecies" inManagedObjectContext:context];

    [SetDB setValue:speciesName forKey:@"favspecies"];
    [SetDB setValue:speciesId forKey:@"ID"];
    [SetDB setValue:Imagename forKey:@"speciesimage"];

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

Can any one help me?

  • 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-06T18:08:54+00:00Added an answer on June 6, 2026 at 6:08 pm

    Actually i made a mistake in my code. The above code was running in aloop. so when i deleted it the insertion was not performing. So i made another method to delete the database and called that method before calling this one. Hence got it working.

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

Sidebar

Related Questions

my iPhone application should store some data persistantly by using Core Data functionality. Here
I'm using core data in my app. I have two entities that are related:
I'm using Core Data to persist some information in a SQLite database. I'm testing
I have an App using core data with 3 entities with very similar attributes.
I've been creating an iPhone App using Core Data. First of all, does it
I have developed my app using core data. It works fine in the simulator.
I'm using an NSDecimalNumber to store money in Core Data. I naively used stringWithFormat:
I’m in the process of designing an iPhone app, using Core Data for data
In my app I am using core data and uses version 1 to 5.
Im using a Core Data model for my iPhone app. I have been looking

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.