As some know, I just started with Objective-C with Steve Kochan's book. Well, one of the exercises told me to write a program to display coordinates. So I wrote one, then checked it online. I did a few things wrong but very minimal. But, I just realized when I checked again, something was weird. Here is the code:
At the top where it says #include <objc/Object.h>, I never saw that before. Can someone explain to me what it means, where it is used, and why I didnt use #import <stdio.h> and #import <objc/Object.h>. Sorry if you see more and more posts by me on this forum as I start to need some more help. Don't think of it as spamming. Thanks
Code:
//Program to weirdly work with coordinates
#include <objc/Object.h>
//@ Interface Section
@interface Point: Object
{
int x;
int y;
}
-(void) setX: (int) xVal;
-(void) setY: (int) yVal;
-(int) x;
-(int) y;
@end
//@ Implementation Section
@implementation Point
-(void) setX: (int) xVal
{
x = xVal;
}
-(void) setY: (int) yVal
{
y = yVal;
}
-(int) x
{
return x;
}
-(int) y
{
return y;
}
@end
//Program Section
int main (int argc, char *argv[])
{
Point *pt1, *pt2;
pt1 = [[Point alloc] init];
pt2 = [[Point alloc] init];
[pt1 setX: 300];
[pt1 setY: 100];
[pt2 setX: 50];
[pt2 setY: 100];
printf ("Pt1 = %i, %i)\n", [pt1 x], [pt1 y]);
printf ("Pt2 = %i, %i)\n", [pt2 x], [pt2 y]);
[pt1 free];
[pt2 free];
return 0;
}