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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:09:42+00:00 2026-06-03T10:09:42+00:00

I have an entity in my core data model like this: @interface Selection :

  • 0

I have an entity in my core data model like this:

@interface Selection : NSManagedObject

@property (nonatomic, retain) NSString * book_id;
@property (nonatomic, retain) NSString * contenu;
@property (nonatomic, retain) NSNumber * page_id;
@property (nonatomic, retain) NSNumber * nbrOfOccurences;
@property (nonatomic, retain) NSString * next;
@property (nonatomic, retain) NSString * previous;

I have created many Selections and saved them in Core Data and now I would like to delete some selections with some criteria. For example, I would like to delete a Selection object if matches the following:

content = test
page_id = 5
book_id = 1331313

How I can do this?

  • 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-03T10:09:43+00:00Added an answer on June 3, 2026 at 10:09 am

    What Mike Weller wrote is right. I’ll expand the answer a little bit.

    First you need to create a NSFetchRequest like the following:

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];    
    [fetchRequest setEntity:[NSEntityDescription entityForName:@"Selection" inManagedObjectContext:context]];
    

    Then you have to set the predicate for that request like the following:

    [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"content == %@ AND page_id == %@ AND book_id == %@", contentVal, pageVal, bookVal]];
    

    where

    NSString* contentVal = @"test";
    NSNumber* pageVal = [NSNumber numberWithInt:5];
    NSString* bookVal = @"1331313";
    

    I’m using %@ since I’m supposing you are using objects and not scalar values.

    Now you perform a fetch in the context with the previous request:

    NSError* error = nil;
    NSArray* results = [context executeFetchRequest:fetchRequest error:&error];
    

    results contains all the managed objects that match that predicate.

    Finally you could grab the objects and call a deletion on them.

    [context deleteObject:currentObj];
    

    Once done you need to save the context as per the documentation.

    Just as a new object is not saved to the store until the context is saved, a deleted object is not removed from the store until the context is saved.

    Hence

    NSError* error = nil;
    [context save:&error];
    

    Note that save method returns a bool value. So you can use an approach like the following or display an alert to the user. Source NSManagedObjectContext save error.

    NSError *error = nil;
    if ([context save:&error] == NO) {
        NSAssert(NO, @"Save should not fail\n%@", [error localizedDescription]);
        abort();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have data model like this Entity: Store Entity: Inventory Entity:Product Attribute:
I have a Core Data model similar to this: Company Entity companyName attribute (string)
I have a Core Data model setup like so: Blockbuster Entity To-Many relationship to
Lets say I have a core data model like this one: Item attributes: name
In my core data model I have a Person entity that has a to
I have set up a Core Data model that includes an entity, Item with
I have a Core Data entity which needs a gender property. I just need
My Core Data model looks like this: alt text http://fwdr.org/lg4q The players relationship of
I have a core data model object called Entry. In this I have an
I have an entity called Task in my Core Data model. The Task entity

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.