Steve, et al.
Your criticism is needed!
XYPoint.h
#import <Foundation/Foundation.h>
@interface XYPoint : NSObject <NSCopying> {
int x;
int y;
}
@property int x, y;
-(id) initWithPt: (int) ptX andPtY: (int) ptY;
-(void) dealloc;
@end
XYPoint.m
#import "XYPoint.h"
@implementation XYPoint
@synthesize x, y;
-(id) initWithPt: (int) ptX andPtY: (int) ptY
{
self = [super init];
if (self)
{
[self setX: ptX];
[self setY: ptY];
}
return self;
}
-(void) dealloc
{
[super dealloc];
}
-(id) copyWithZone: (NSZone*) zone
{
XYPoint *newPt = [[ XYPoint allocWithZone:zone] init];
[newPt initWithPt: self.x andPtY: self.y];
return newPt;
}
@end
Rectangle.h
#import <Foundation/Foundation.h>
#import "XYPoint_18.h"
@interface Rectangle : NSObject <NSCopying> {
int width;
int height;
XYPoint *origin;
}
@property int width, height;
@property (copy, nonatomic) XYPoint *origin;
-(void) setWidth: (int) w andHeight: (int) h;
-(int) area;
-(int) perimeter;
-(void) print;
-(void) dealloc;
@end
Rectangle.m
#import "Rectangle.h"
@implementation Rectangle
@synthesize width, height, origin;
-(void) setWidth: (int) w andHeight: (int) h
{
[self setWidth: w];
[self setHeight: h];
}
-(int) area
{
return self.width * self.height;
}
-(int) perimeter
{
return 2 * ( self.width + self.height);
}
-(void) print
{
NSLog(@"\nWidth: %i\nHeight: %i\nOrgin: x: %i y %i", self.width, self.height, self.origin.x, self.origin.y);
}
-(id) copyWithZone: (NSZone *) zone
{
Rectangle *newRect = [ [ Rectangle alloc] init];
[newRect setWidth: self.width andHeight: self.height];
[newRect setOrigin: [origin copy]];
return newRect;
}
-(void) dealloc
{
[origin release];
[super dealloc];
}
@end
test Program main.m
#import "Rectangle.h"
#import "XYPoint.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
XYPoint *pt = [[XYPoint alloc] initWithPt:45 andPtY: 78];
Rectangle *myRect = [[Rectangle alloc] init], *copiedRect;
[myRect setWidth: 100 andHeight: 34];
[myRect setOrigin: pt];
NSLog(@"Print all values assigned to Rectangle");
[myRect print];
NSLog(@"Copy rectangle");
copiedRect = [myRect copy];
NSLog(@"Print all values assigned to copy");
[copiedRect print];
[copiedRect release];
[myRect release];
[pool drain];
return 0;
}
As to the question of mutable/immutable copies...hmm!

The values one is working with are not really foundation classes, so not sure how mutability would affect these?