سؤال

I am using storyboard in one of my application and while passing a property from SourceViewController to DestinationViewController in prepareForSegue method the property being passed is passed by reference instead of passed by value. Which is causing some trouble for me as in Destination View Controller if user fiddles with the values and taps on back then I get an updated value in my SourceViewController which I do not want.

Please see the following to get more information on the issue

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{if([[segue identifier] isEqualToString:@"DestinationView"])
    {
        DestinationViewController  *destinationViewController = [segue destinationViewController];
        [destinationViewController setActivity:activity];
        //Here the value of activity is passed by reference. I have verified the same by checking the address of activity variable in Variable pane of Xcode in Source and destination view controller
}

Now I am not sure how to only pass the value and not the reference in the above case.

هل كانت مفيدة؟

المحلول

try to use a copy of it

    [destinationViewController setActivity:[activity copy]];

Implement its delegate copywithZone if needed

- (id)copyWithZone:(NSZone *)zone
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top