I have seen two some a bit different ways for implementing copyWithZone. Are they different?
1st code:
@interface Person : NSObject <NSCopying>
@property (nonatomic,weak) NSString *name;
@property (nonatomic,weak) NSString *surname;
@property (nonatomic,weak) NSString *age;
-(id) copyWithZone:(NSZone *)zone;
@end
//and 1st implementation
@implementation Person
-(id) copyWithZone:(NSZone *)zone
{
Person *copy = [[self class] allocWithZone:zone];
copy.name = self.name; //should we use copy.name=[self.name copyWithZone: zone]; ?
copy.age = self.age;
copy.surname = self.surname; //here we make assignment or copying?
return copy;
}
@end
and 2nd code
@interface YourClass : NSObject <NSCopying>
{
SomeOtherObject *obj;
}
// In the implementation
-(id)copyWithZone:(NSZone *)zone
{
// We'll ignore the zone for now
YourClass *another = [[YourClass alloc] init];
another.obj = [obj copyWithZone: zone];
return another;
}
If they are different, what's of them more correct? 1. I confused with [self class] in 1st. I know about meta-classes in objective c, but is it necessary in that chunk of code? 2. copy.name = self.name; vs another.obj = [obj copyWithZone: zone] What's the difference between aforesaid?