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

The Archive Base Latest Questions

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

In a Navigation based app, I’d like to be able to have a Clone

  • 0

In a Navigation based app, I’d like to be able to have a “Clone” or “Save As” button on my detailed Product view where a user can create a new Product from one of their existing products they have already entered. In the app, a product has quite a few attribute fields for the user to enter, so I’d like to offer the ability for a user to quickly “Clone” or “Save As” any of their existing products which would automatically copy the attributes of that existing Product over to a new product and allow the user to enter a name for the new Product and save it.

Any help with how to achieve this would be much appreciated. Thanks.

  • 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-23T02:21:18+00:00Added an answer on May 23, 2026 at 2:21 am

    I’m assuming that you are using Core Data, but you don’t specifically mention that. From the context of your question, that seems to make sense.

    Copying properties from one object to another can be tricky. I recommend a great book on Core Data by Marcus Zarra. You can find it here http://pragprog.com/titles/mzcd/core-data

    In his book, he runs through this through this scenario except in the context of importing and exporting data, but the code should be similar. Here is some code that is available from his book site (above). This copies all properties, including relationships, from one object to another. You must also identify the name of the parent object in order for it to work properly.

    This code will not only copy properties, but also relationships, including related objects and their properties. It works quite well.

    Hope this helps!

    - (void)copyPropertiesFromObject:(NSManagedObject*)oldObject
                        toObject:(NSManagedObject*)newObject
                          parent:(NSString*)parentEntity {
    
    NSString *entityName = [[oldObject entity] name];
    NSArray *attKeys = [[[oldObject entity] attributesByName] allKeys];
    NSDictionary *attributes = [oldObject dictionaryWithValuesForKeys:attKeys];
    [newObject setValuesForKeysWithDictionary:attributes];
    //END:copyPropertiesFromObjectProperties
    
    //START:copyPropertiesFromObjectRelationships
    id oldDestObject = nil;
    id temp = nil;
    NSDictionary *relationships = [[oldObject entity] relationshipsByName];
    for (NSString *key in [relationships allKeys]) {
        NSRelationshipDescription *desc = [relationships valueForKey:key];
        NSString *destEntityName = [[desc destinationEntity] name];
        if ([destEntityName isEqualToString:parentEntity]) continue;
    
        if ([desc isToMany]) {
            NSMutableSet *newDestSet = [NSMutableSet set];
            for (oldDestObject in [oldObject valueForKey:key]) {
                temp = [[self lookup] objectForKey:[oldDestObject objectID]];
                if (!temp) {
                    temp = [self associateObject:oldDestObject 
                                parent:entityName];
                }
                [newDestSet addObject:temp];
            }
            [newObject setValue:newDestSet forKey:key];
        } else {
            oldDestObject = [oldObject valueForKey:key];
            if (!oldDestObject) continue;
            temp = [[self lookup] objectForKey:[oldDestObject objectID]];
            if (!temp) {
                temp = [self associateObject:oldDestObject 
                                      parent:entityName];
            }
            [newObject setValue:temp forKey:key];
        }
    }
    }
    

    And this:

    - (id)associateObject:(NSManagedObject*)object parent:(NSString*)name {
    
    NSManagedObjectContext *moc = [self mainContext];
    NSString *entityName = [[object entity] name];
    id temp = nil;
    
    if ([entityName isEqualToString:@"Title"]) {
        temp = [NSEntityDescription insertNewObjectForEntityForName:entityName 
                                         inManagedObjectContext:moc];
        [[self lookup] setObject:temp forKey:[object objectID]];
        [self copyPropertiesFromObject:object toObject:temp parent:name];
        return temp;
    }
    
    if ((temp = [self objectOfType:entityName 
                         withName:[object valueForKey:@"name"]])) {
        [[self lookup] setObject:temp forKey:[object objectID]];
        return temp;
    }
    
    temp = [NSEntityDescription insertNewObjectForEntityForName:entityName
                                         inManagedObjectContext:moc];
    [[self lookup] setObject:temp forKey:[object objectID]];
    [self copyPropertiesFromObject:object toObject:temp parent:name];
    return temp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController inside of a navigation based app. I'd like the view
I have a navigation based app. Press a button on main view, then I
I'm writing a Navigation-Based iPhone app, and I'd like to have a UIToolBar docked
I have a navigation based app where a certain pushed view has a nice
I have a navigation controller-based app in which I would like to temporarily disable
I have a view based app (not navigation or tab based...) My main view
I have a tab bar + navigation based app and I'd like to launch
i have a navigation-based app. the first view is a tableView, when i press
I have a fairly straight-forward navigation based app. It is like a wizard in
I have a navigation based app. The first view (rootcontroller) starts with three large

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.