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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:18:45+00:00 2026-05-23T00:18:45+00:00

Possible Duplicate: deep copy NSMutableArray in Objective-C ? I have two arrays of length

  • 0

Possible Duplicate:
deep copy NSMutableArray in Objective-C ?

I have two arrays of length 5 with items of a custom class I’ve built. I want to copy the first array into the second. Once copied I want these two arrays to be totally independent (I want to be able to change the first without affecting the second). I have tried several methods to no avail (when I make a change to one, the other is changed as well). They are shown below.

1)

[[NSArray alloc] initWithArray:self.lifelineList copyItems:YES];

My copying protocol for this method is:

- (id) copyWithZone:(NSZone *)zone{
Lifeline *lifelineCopy = [[Lifeline allocWithZone:zone]init];
lifelineCopy.name = name;
lifelineCopy.phone = phone;
lifelineCopy.email = email;
lifelineCopy.isActive = isActive;
lifelineCopy.contactID = contactID;
return lifelineCopy;
}

2)

[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject: self.lifelineList]];  

My coding protocol for this method is:

- (id) initWithCoder:(NSCoder *)aDecoder{
if (self=[super init]){
    self.name = [aDecoder decodeObject];
    self.phone = [aDecoder decodeObject];
    self.email = [aDecoder decodeObject];
    self.contactID = [aDecoder decodeIntegerForKey:@"contactID"];
    self.isActive = [aDecoder decodeIntegerForKey:@"isActive"]>0;
}
return self;
}
- (void) encodeWithCoder:(NSCoder *)aCoder{
[aCoder encodeObject:self.name];
[aCoder encodeObject:self.phone];
[aCoder encodeObject:self.email];
[aCoder encodeInteger:self.contactID forKey:@"contactID"];
[aCoder encodeInteger:(NSInteger)self.isActive forKey:@"isActive"];
}

3) iterate through the first array, put the instance variables of each element into a temporary variable and then add that variable to the second array.

I am happy to post more code if needed.

  • 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-23T00:18:46+00:00Added an answer on May 23, 2026 at 12:18 am
    1. Is your custom class properly implementing the NSCopying protocol? (I.e. implement copyWithZone: to return a completely independent instance.)

    2. Is you custom class properly implementing the NSCoding protocol to archive and decode all of the relevant instance variables?

    3. This won’t work unless you actually copy the objects themselves. Simply assigning to a temporary variable does nothing at runtime.

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

Sidebar

Related Questions

Possible Duplicate: What's the best way to make a deep copy of a data
Possible Duplicate: What is the difference between a deep copy and a shallow copy?
Possible Duplicate: What's the best way to make a deep copy of a data
Possible Duplicate: What is the best way to clone/deep copy a .NET generic Dictionary<string,
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicates: Deep copy vs Shallow Copy In Java, what is a shallow copy?
Possible Duplicate: Copy a linked list Hello stackoverflow! I am trying to learn more
Possible Duplicate: Interface vs Abstract Class (general OO) Hi guys, I decided to dig
Possible Duplicate: How to detect if JavaScript is disabled? I have a website which

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.