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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:58:48+00:00 2026-06-15T04:58:48+00:00

I am not even sure if I am stating this right but I am

  • 0

I am not even sure if I am stating this right but I am trying to copy a user created coredata object intstance and having a pretty hard time figuring it out.

I have an object (Question) that is pulled in from the managedObjectContext.

This is from a Quiz in my database that has many Questions.

I have my Question instance in memory named question1. I want to copy question1 to an instance called question2.

Question *question2 = question1;

Works sometimes but crashes sometimes too (I know its not the right way to do it)

I have been messing with NSCopying and -(id)copyWithZone:(NSZone *) zone but I am just getting a blank instance back.

If anyone could help that would be great thanks!

Here is a little bit more detail.

I have question1 it is an instance of Question. for example question1.answer will return that questions answer.

I want to simply copy question1 to question2. I dont need to store question2 in the datamodel or anything I just need to use it in a loop then release.

Basically I want to do this:

Question *question2 = question1;
NSLog(@"%@", question2.answer)

The above is working sometimes but then sometimes I am getting random crashes on the nslog line.

  • 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-15T04:58:49+00:00Added an answer on June 15, 2026 at 4:58 am

    You have to create a new object in the managed object context and then copy all attributes and relationships:

    Question *question2 = [NSEntityDescription
                               insertNewObjectForEntityForName:@"Question"
                               inManagedObjectContext:context];
    // Copy attributes:
    question2.attr1 = question1.attr1;
    question2.attr2 = question1.attr2;
    // ...
    // Copy relationships:
    question2.rel1 = question1.rel1;
    // ...
    

    This can be automated using the NSEntityDescription of question1 and processing all attributes and relationships from the entity description, see the (great) answer to this question: How can I duplicate, or copy a Core Data Managed Object?. But note that that code duplicates also all related objects, which might not be what you want.

    I think that if there are not too many attributes/relationships, the “manual” copying is easier, and you can decide for each related object if that must also be copied or not.

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

Sidebar

Related Questions

I'm not even sure what this is called? But I'm trying to learn what
Not even sure how to explain this but I connect to a remote computer
Im not even sure how to ask this question, but i'll give it a
Hello! I'm not even sure if this is possible, but hopefully it is in
I am not sure why this is not working but what I am trying
Not even sure I'm stating the question correctly. Here's the situation. I have a
I'm not even sure how I should phrase this question. I'm passing some CustomStruct
I'm not even sure what this principle is called or how to search for
I am not even sure how to ask this question. I want something that
I am not sure whether this is the right place to ask this question.

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.