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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:55:20+00:00 2026-05-25T20:55:20+00:00

I need to delete the selected row of the database shown in updatePick ,

  • 0

I need to delete the selected row of the database shown in updatePick, but can’t seem to get the managedObject that’s supposed to be in the [context deleteObject:managedObject]; line correct. Here’s the deleteUpdate method:

-(void)deleteUpdate {
    NSLog(@"35-Delete pressed.");
    NSManagedObjectContext *context = [self managedObjectContext];
    NSEntityDescription *updateEntity = [NSEntityDescription entityForName:@"Updates" inManagedObjectContext:context];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:updateEntity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dateGains = %@)", [arrayNSDateGains objectAtIndex:updatePick]];
    [fetchRequest setPredicate:predicate];

    NSArray *gains = [context executeFetchRequest:fetchRequest error:nil];

    for (updateGains in gains) {
        [context deleteObject:updateGains];
    }
    [self saveContext];
}

This manages to delete the contents of the row in the database (YEAH), except, it leaves an empty row and three residual elements: primary key (Z_PK), and two integers (Z_ENT) & (Z_OPT). The empty row causes errors elsewhere. What am I missing here?

  • 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-25T20:55:20+00:00Added an answer on May 25, 2026 at 8:55 pm

    Core Data often leaves empty rows in sqlite stores after deletes. The documentation explicitly states that the store file will not grow smaller after deletes until at some arbitrary point the persistent store object decides to condense the store.

    In general looking at the sqlite store itself is a waste of time. Core Data is not SQL. Entities are not tables. Objects are not rows. Attributes are not columns. Relationships are not joins. Core Data is an object graph management system that may or may not persist the object graph and may or may not use SQL far behind the scenes to do so. Trying to think of Core Data in SQL terms will cause you to completely misunderstand Core Data and result in much grief and wasted time.

    Core Data merely has the option of serializing (freeze drying) object into an sqlite store. However, how it does that is not documented so looking at the sqlite store directly won’t tell you much.

    The only way to confirm that an object has been deleted is to get and save its permenent managedObjectID. After the delete, ask the persistentStoreCoordinator to fetch the object for the id with objectWithID:. If the object has been deleted, it won’t find it.

    There are only a couple of ways in which an object can remain after deletion. The undo manager can roll back apparent deletions but that isn’t the case here. If you retain a managed object elsewhere, then the object in memory will remain after the deletion (although it won’t show up in Core Data operations like a fetch.)

    I doubt any problems you are having is caused by an issue with the store. Such issues are very rare.

    Update:

    After the save, I do a [self setNeedsDisplay]; which triggers a
    redrawing of the bar chart based on the data in the database. The
    first mutable array tries to insertObject:atIndex: a nil object which
    causes crash…
    I’ve inserted a if(dateGained==nil) continue; at the point where the
    next error had occurred and it works great.

    Your problem here is that your UI controller is not updating its count of the managed objects after the context deletes some of them.

    For example: You have a table that displays one Update object per row. At the start the UI controller fetches all the existing Update objects. It tells the table that it has [fetchObjects count]. Then you delete some of the Update objects but then you don’t tell the table it has fewer rows now. The table will attempt to access objects in the array past the last element which causes a crash.

    The solution here is to register your controller for the context’s notification:

    NSManagedObjectContextObjectsDidChangeNotification

    … and then update the array and the tables row count before you call [self setNeedsDisplay].The table will then understand how many rows it should have.

    Any UI element that depends on a count of the fetched objects needs to keep in sync with changes in object graph, especially deletes.

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

Sidebar

Related Questions

I need to delete the latest browser history entry for this reason , but
How can I delete a specific row from an sql table? I have a
I fetch data in table. but i need to delete it when user click
In the attached screen shot you can she that to rename a selected tab
I need to know how to delete a selected record from a datarepeater. I
By default, I can see Delete the selected user action from django user admin
I need to delete a temporary file from my C++ windows application (developed in
I need to delete a regsitry key. It has a deny ACL on Set
I need to delete some Unicode symbols from the string 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ'
I need to delete my input file securely once I have finished with it,

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.