@interface Shape : NSObject<NSCopying>
@property int lineCount;
@property NSString *name;
-(id)copyWithZone:(NSZone *)zone;
-(id) initWithName: (NSString *) name lineCount: (int) lineCount;
@end
@implementation Shape
-(id)copyWithZone:(NSZone *)zone {
return [[Shape alloc] initWithName:_name lineCount:_lineCount];
}
-(id) initWithName: (NSString *) name lineCount: (int) lineCount {
self = [super init];
if (self) {
self.name = name;
self.lineCount = lineCount;
}
return self;
}
@end
Shape *square = [[Shape alloc] initWithName:@"Square" lineCount:4];
Shape *squareCopy = [square copyWithZone:nil];