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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:34:23+00:00 2026-06-06T22:34:23+00:00

Using core data I’d like to fetch some data. My model uses some abstract

  • 0

Using core data I’d like to fetch some data. My model uses some abstract entities, see attached picture, where QuantifiedIngredient is an abstract class.
I’d like to fetch Ingredient entities that have at least one RecipeQuantifiedIngredients, but in the middle is QuantifiedIngredient, which is an abstract class.

How can I do that, how can I test the actual type of an abstract class inside a NSPredicate? Any idea or suggestion?

enter image description here

The only clue I found was:
How can you reference child entity name in a predicate for a fetch request of the parent entity?

Would work a custom property in my QuantifiedIngredient to know if it is a RecipeQuantifiedIngredient? For instance isRecipeQuantifiedIngredient?

Thanks a lot for your help.

  • 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-06T22:34:25+00:00Added an answer on June 6, 2026 at 10:34 pm

    I don’t want to take the time to translate this into CoreData-speak so here is my thought in SQL:

    SELECT * FROM quantifiedIngredients WHERE recipe <> NULL
    

    or something like that. This is essentially Nikita’s suggestion of using a flag, except that the ‘flag’ is the existence of a property. I don’t know how CoreData will react when faced with GroceryQuantifiedIngredients that don’t have the recipe, I think KVO will throw an exception. You might be so bold as to add a category:

    @interface GroceryQuantifiedIngredients (KVOHack)
    -(id)recipe;
    @end
    
    @implementation GroceryQuantifiedIngredients (KVOHack)
    -(id) recipe { return nil; }
    @end
    

    This would of course require CoreData to enumerate all quantifiedIngredients, but I presume it will have to do so anyway, and a the return nil should optimize into tiny code. The other consideration is whether this will have a bad effect on the rest of your code; you will have to make that call.

    Another idea which pops to mind as I finish this up is to do something like this (I’m getting really loose with my pseudo-code now):

    SELECT * FROM quantifiedIngredients WHERE [i respondsToSelector:@selector(recipe)];
    

    See what I mean? I forget whether CoreData lets you play with some kind of cursor when working with predicates or fetchedThingamabobbers, if it does than I think this is your best bet. Anyway it’s Sunday afternoon so that stuff is left as a exercise for the reader.

    +1 for a good question.

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

Sidebar

Related Questions

I am using core data to store some details. But when I run my
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 am using Core Data for my app and I have a model Reservation
I am using core data and am generating classes from my data model. I
Using Core Data, I have a fetch request to fetch the minimum of a
I'm using Core data in an iOS project. I have the data model setup
I am using Core Data programmatically (i.e. not using .xcdatamodel data model files) in
I'm using core data and I have a simple two-entity model. My navigation controller

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.