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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:48:33+00:00 2026-05-17T02:48:33+00:00

I have a CoreData model (managed object) called Item: @interface Item : NSManagedObject {

  • 0

I have a CoreData model (managed object) called Item:

@interface Item :  NSManagedObject {
  NSString * type;
}
@property (retain) NSString * type;
@end

I also have two subclasses of Item:

@interface Circle : Item
@end

@interface Square : Item
@end

I track the subclass of the item by the type property.

When I fetch my Items, I get back an array of Items. But I want to be able to dynamically typecast the items according to their type.

Does CoreData support this natively? If not, is there a way to dynamically typecase each Item?

I can get the class that I want to cast the Item as like:

Item * item = ...;
id klass = NSClassFromString(item.type);

I just don’t know how I can cast item as type klass.

  • 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-17T02:48:33+00:00Added an answer on May 17, 2026 at 2:48 am

    Yes it’s built in. You don’t have to do it manually. You don’t even have to put the type entry yourself.

    In Objective-C there’s the concept of superclass / subclass .
    Correspondingly, in Core Data, there’s the concept of parent entity / child entity. This can be specified in the model file.

    In the Core Data modeler, create two entities Circle and Square by inheriting your Item entity. You can specify the parent of the entity in the modeler. Then, in the modeler, specify the custom class Circle for your entity Circle, the class Square for the entity Square.

    Then, when you fetch the managed object from the database, the correct class is automatically assigned.
    Read the documentation of the modeler.

    Again, everything can be done in the modeler, without your writing anything.

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

Sidebar

Related Questions

In my Core Data managed object model, I have an entity Foo with a
I have a CoreData model with 2 objects. The first object (Images) contains a
I am struggling with designing a coreData model where I have only one type
I have a sqlite DB created by my CoreData model automatically, but my app
I have an old Xcode project which contains a CoreData model (containing a version
I have set up a Core Data model that includes an entity, Item with
I have an attribute called phoneNo in my Core Data model, an integer16 ,
I'm wanting to make a CoreData entity called Employees, some Employees could have a
Say I have 2 managed objects in my model: Department and Employee (as discussed
How do you change the filename of a Core Data managed object model? I

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.