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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:37:39+00:00 2026-06-05T19:37:39+00:00

I have an object called Layer that has some attributes and some methodes. i

  • 0

I have an object called Layer that has some attributes and some methodes.

i need to pass Layer to a second view controller:

SecondVC *view = [self.storyboard instantiateViewControllerWithIdentifier:@"2VC"];
view.Layer = [[Layer alloc] initWithMapLayer:self.Layer];
view.delegate = self;

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:view];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:navController animated:YES];

in the SecondVC, i may change the attributes. I then return the Layer object back via a delegate;

-(void)done
{
    [self.delegate returnLayer:self.layer];

    [self dismissModalViewControllerAnimated:YES];
}

now my problem is that i am passing a pointer to my first view controller’s Layer object and when i update the Layer in the second view controller, my first view controller’s Layer object is also being updated.

because of this, i can’t tell if it has been changed (if it has, i need to run some code).

how can i create a copy of my Layer object and pass that instead of a pointer to my first view controller’s Layer object?

EDIT:

i did try use a second init method:

-(id)initWithLayer:(Layer *)Layer
{
    if (self = [super init])
    {
        self.call = [[FunctionCall alloc] init];        
        self.HUD = [[MBProgressHUD alloc] init];

        self.Layers = [[NSMutableDictionary dictionaryWithDictionary:Layer.Layers] copy];
        self.nameList = [[NSArray arrayWithArray:Layer.nameList] copy];
    }
    return self;
}

which did not work out.

EDIT2:

tried

Layer *copyLayer = [self.myLayer copy];

layerView.myLayer = copyLayer;

and got error

-[layer copyWithZone:]: unrecognized selector sent to instance 0xfc72c40
2012-06-12 11:15:28.584 Landscout[8866:1fb07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Layer copyWithZone:]: unrecognized selector sent to instance 0xfc72c40'

SOLVED:

i added a deep copy to the initWithLayer method:

for (id key in layer.layers)
{
    [newLayers setValue:[[layer.layers objectForKey:key] mutableCopy] forKey:[key mutableCopy]];
}

for (id name in layer.nameList)
{
    [newList addObject:[name mutableCopy]];
}

this gives me a copy of the Layer object

  • 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-05T19:37:41+00:00Added an answer on June 5, 2026 at 7:37 pm

    You will need to implement copy function to your object

    In your Layer.m

    - (id)copy
    {
        Layer *layerCopy = [[Layer alloc] init];
    
        //YOu may need to copy these values too, this is a shallow copy
        //If YourValues and someOtherValue are only primitives then this would be ok
        //If they are objects you will need to implement copy to these objects too
        layerCopy.YourValues = self.YourValues;
        layerCopy.someOtherValue = self.someOtherValue;
    
        return layerCopy;
    }
    

    Now in your calling function

    //instead of passing self.Layer pass [self.Layer copy]
    view.Layer = [[Layer alloc] initWithMapLayer:[self.Layer copy]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent object called Page that has a List of objects called
I have an object called users that I use to store user objects that
I have an object called Contact. A Contact has a relationship with a set
Here is the scenario: I have an object called a Transaction that needs to
I have an object class called BOM. It has a method, getChildItem() which returns
I have a UITableView that displays various nsstrings from a custom object called a
I have an object with a property called name. This object has a sub
I have a data object -- a custom class called Notification -- that exposes
I have a repository layer that is responsible for my data-access, which is called
I have an NSDate object called 'dueDate'. I'm trying to work out how to

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.