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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:30:10+00:00 2026-06-05T10:30:10+00:00

I am trying to create a new entity using an existing entity (passed in)

  • 0

I am trying to create a new entity using an existing entity (passed in) set set all the values . Here is the class method that I am using in the Managed Object Subclass:

+(FlightManifest *)getNextFlightManifestLegWithFlightManifest:(FlightManifest *)fm {
    // Get the current context
    NSManagedObjectContext *moc = [NSManagedObjectContext MR_contextForCurrentThread];

    // Set a var to the cur leg so we can use it to increment the leg number later
    NSInteger curLeg = [fm.leg intValue];

    // Check to see if we already have the next leg saved
    if ([self getFlightManifestWithTripID:fm.tripid andLeg:[NSNumber numberWithInt:curLeg + 1]] !=nil) {
        return [self getFlightManifestWithTripID:fm.tripid andLeg:[NSNumber numberWithInt:curLeg + 1]];
    } else {
        // Create a new leg using the passed in FlightManifest for the values
        FlightManifest *newFM = [FlightManifest MR_createInContext:moc];  

        // Set the value of the newly created object to the one passed in
        newFM = fm;

        // Increment the leg number
        newFM.leg = [NSNumber numberWithInt:curLeg + 1];

        // Save the object
        [moc MR_save];

        return newFM;
    }
}

And I call it like this:

- (IBAction)nextLegButtonPressed:(id)sender {

    currentFlight = [FlightManifest getNextFlightManifestLegWithFlightManifest:currentFlight];
    self.legNumberLabel.text = [currentFlight.leg stringValue];
    [self reloadLegsTableViewData];
}

What is happening is that I am changing the current entity instead of creating a new one. Any ideas on what I am doing wrong?

  • 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-05T10:30:11+00:00Added an answer on June 5, 2026 at 10:30 am

    This may seem obvious, but this line seems suspicious:

    // Set the value of the newly created object to the one passed in
        newFM = fm;
    

    This would make the code after use the existing fm object…and change the one your trying to copy…

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

Sidebar

Related Questions

I am trying to create a new dict using a list of values of
I am trying to create a new contact using Dynamic Entity. The sample i
I'm using Entity Framework Code First. The class i'm trying to create contains two
I'm trying to create a new project in NetBeans PHP from existing sources. When
I am trying to create a new branch using the API, and have used
I'm trying to create a simple table navigation screen in WPF using the entity
I'm trying to create a new entity and have it appear in the 'My
I am trying to create a completely dynamic way to query entity framework using
I am trying to create an instance of an Entity Framework object using reflection:
I am trying to create WCF Data service project using Entity Framework. ( 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.