The @class Directive
Now you can work with rectangles (and squares as well!) with the ability to set their widths, heights, and origins. First, let’s take a complete look at your Rectangle.h
interface file:
#import <Foundation/Foundation.h>@class XYPoint;@interface Rectangle: NSObject@property int width, height;-(XYPoint *) origin;-(void) setOrigin: (XYPoint *) pt;-(void) setWidth: (int) w andHeight: (int) h;-(int) area;-(int) perimeter;@end
You used a new directive in the Rectangle.h
header file:
@class XYPoint;
You needed this because the compiler needs to know what an XYPoint
is when it encounters it as one of the instance variables defined for a Rectangle
. The class name is also used in the argument and ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.