1

How do i make a deep copy using copyWithZone so that each object in array1 is duplicated in the array2 with its own copy. So if i make changes in array1 it wont affect array2

this is main.m

@autoreleasepool {

    NSArray *array1 = @[fbUser1, fbUser2, fbUser3];
    NSArray *array2 = [array1  copy];
}

this is UserClass.h

@interface FbUser : NSObject <NSCopying>{
}

now in UserClass.m i have copyWithZone

- (id)copyWithZone:(NSZone *)zone
{
    id copy = [[[self class] alloc] init];

    if (copy) {

    }

    return copy;
}

I have searched the docs but could not get it to work. Any help would be highly appreciated.

Fahad Ajmal
  • 1,520
  • 1
  • 12
  • 15
  • 1
    Answer in this link might help you http://stackoverflow.com/questions/5453481/how-to-do-true-deep-copy-for-nsarray-and-nsdictionary-with-have-nested-arrays-di and http://stackoverflow.com/questions/4089238/implementing-nscopying – Pushpak Narasimhan May 02 '14 at 07:02

0 Answers0