Rectangle
在我遗漏的实施部分中,#import "XYpoint"
它对我来说仍然有效。是在进行#import "XYpoint"
良好的实践还是会影响计划?
#import <Foundation/Foundation.h>
@interface XYPoint : NSObject
@property int x, y;
-(void) setX: (int) xVar andY: (int) yVar;
@end
#import "XYpoint.h"
@implementation XYPoint
@synthesize x, y;
-(void) setX:(int)xVar andY:(int)yVar {
x = xVar;
y = yVar;
}
@end
#import <Foundation/Foundation.h>
@class XYPoint;
@interface Rectangle: NSObject
-(XYPoint *) origin;
-(void) setOrigin: (XYPoint *) pt;
@end
#import "Rectangle.h"
#import "XYpoint.h"
@implementation Rectangle {
XYPoint *origin;
}
-(void) setOrigin:(XYPoint *)pt {
origin = pt;
}
-(XYPoint *) origin {
return origin;
}
@end
#import "XYpoint.h"
#import "Rectangle.h"
int main (int argc, char * argv[]) {
@autoreleasepool {
Rectangle *rect = [[Rectangle alloc] init];
XYPoint *pointy = [[XYPoint alloc] init];
[pointy setX:5 andY:2];
rect.origin = pointy;
NSLog(@"Origin %i %i", rect.origin.x, rect.origin.y);
}
return 0;
}