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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:06:42+00:00 2026-06-14T20:06:42+00:00

I have 3 entities that I generated with MOGenerator, I’d like to be able

  • 0

I have 3 entities that I generated with MOGenerator, I’d like to be able to get one of them back from their objectID

I tried this :

- (void)aMethod: (SpecialEntity1ID *)entityID
{
    //This is a method from MagicalRecord but it doesn't matter(I think...).
    NSManagedObjectContext *context = [NSManagedObjectContext MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]];

    SpecialEntity1 *entity1 = [context objectRegisteredForID:entityID]
    //But this returns an NSManagedObject so it doesn't work...
}

Could someone help me get this object back with its ID ?

Since I don’t know how to do it with the ID I’m currently working around it by making a method with an NSStringas a paramater instead of SecialEntity1ID that defines one of the attribute of this object (and is unique) and fetching the object.

I think getting back with his ID is better so any idea ?

  • 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-14T20:06:43+00:00Added an answer on June 14, 2026 at 8:06 pm

    You want to use existingObjectWithID:error: method of your NSManagedObjectContext and typecast the return type if you are 100% sure what it will be. I’d keep it generic i.e. let it return an NSManagedObject and then test its class elsewhere if you want to determine whether it belongs to a particular class.

    - (Object*)retrieveObjectWithID:(ObjectID*)theID
    {
        NSError *error = nil;
        Object *theObject = (Object*)[[NSManagedObjectContext contextForCurrentThread] existingObjectWithID:theID error:&error];
        if (error)
            NSLog (@"Error retrieving object with ID %@: %@", theID, error);
        return theObject;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of entities that I generated from a database. One table
I have an ASP.NET MVC3 application that uses entities generated from a database. Each
I have about 8 entities that all have a one to one relationship with
I have 2 NHibernate entities (tables) that are in a one to many relationship.
I have several entities generated from my Entity Framework data model. In the .edmx
This is situation I have: I have two entities with one-to-many relationship mapped like
I am developing using zend framework and doctrine2.1. I have generated entities from database.
I do generate entities from database. Here is a file that I generated before
I'm working on a web application. I have entities that are supposed to be
I have 2 entities that are playing nice together when I am pulling data

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.