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

  • Home
  • SEARCH
  • 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 856345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:13:11+00:00 2026-05-15T08:13:11+00:00

How to group methods belong to one entity in one class file in Core

  • 0

How to group methods belong to one entity in one class file in Core Data like Entity Framework?

In Linq, we can put all methods in the domain object class and reuse them, in Core Data, is there any way to create different classes for different entities? Or we can only use predicate to retrieve?

It seems that I can’t define the class for each entity I configured in the data model. And it is not like hibernate that I can control the physical database schema via ORM. Correct me if I am wrong, I don’t believe Core Data can do this as far I know.

So what is the advantage to use Core Data? And is there any mechanism on Cocoa that I can define my domain object classes including primary key, foreign key, for instance, and then create the database schema then?

It seems like the Core Data can only support configuring the objects but there is even no way to configure the physical database via the Core Data.

  • 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-15T08:13:11+00:00Added an answer on May 15, 2026 at 8:13 am

    In your Core Data model you can define which class to instantiate your entities as:

    alt text http://img404.imageshack.us/img404/3368/setclass.png

    When Core Data fetches objects from the store, it will attempt to create them as instances of this class (although it’s not quite that simple, Core Data does some tricks).

    You can auto-generate class files for your entities by opening your core data model in a new window, and choosing File->New File:

    alt text http://img241.imageshack.us/img241/8238/newfile.png

    You should see a new “Managed Object Class” item:

    alt text http://img46.imageshack.us/img46/348/managedobjectclass.png

    Choose this and select the entities to generate classes for:

    alt text http://img241.imageshack.us/img241/5030/selectentity.png

    A class will be generated with various properties for getting/setting the attributes on your entity:

    alt text http://img10.imageshack.us/img10/9868/generatedproperties.png

    If you want to add your own methods, I would recommend you add them to a separate Category. This is because you will often want to regenerate these core data classes when you add new properties or change the entities. If you make additions directly to these files you will lose your changes the next time you generate them.

    So create a category called Person+Additions or whatever name you think is appropriate:

    alt text http://img294.imageshack.us/img294/8871/addcategory.png

    And add any new methods or properties to this class:

    alt text http://img717.imageshack.us/img717/3884/addmethods.png

    Note that you cannot add new instance variables, but NSManagedObject has facilities to get/set values in an internal dictionary. See the NSManagedObject documentation

    So once you’ve done all this, all you do is cast the NSManagedObject you get from a fetch request (or wherever) to the appropriate type:

    #import "Person+Additions.h"
    
    //...
    
    Person *p = (Person *) [fetchResult objectAtIndex:0];
    [p myCustomMethod];
    
    //...
    

    As for your other questions about primary keys, and interacting with the physical database, this isn’t really what Core Data is designed to provide you. You should not think too much about the underlying database, Core Data is meant to be more high level than that. You define your model, and fetch objects through the API. Primary keys and othe “database-y” details like this are not exposed.

    If you want full control over the database you should use the sqlite APIs. But I would say for the large majority of applications Core Data is the better choice.

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

Sidebar

Related Questions

No related questions found

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.