// // main.m // mylearn // #import <Foundation/Foundation.h> #import "Mypoint.h" @implementation Mypoint @synthesize z; -(void) print{ NSLog(@"(%i,%i)",myx,myy); } -(void)setx:(int)x{ myx=x; } -(void)sety:(int)y{ myy=y; } -(int) myx{ return myx; } -(int) myy{ return myy; } -(void) sayz{ NSLog(@"%i,%i,%i",myx,myy,z); } +(void)sayhello{ NSLog(@"hello"); } -(int)distx1:(int)x1 distx2:(int)x2 disty1:(int)y1 disty2:(int)y2{ return (int)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } @end int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... Mypoint *mypoint; [Mypoint sayhello]; mypoint=[Mypoint alloc]; mypoint=[mypoint init]; [mypoint setx:10]; [mypoint sety:20]; [mypoint setZ:16]; [mypoint sayz]; NSLog(@"dist:%i",[mypoint distx1:10 distx2:6 disty1:9 disty2:28]); NSLog(@"point:"); NSLog(@"%i",[mypoint myx]); [mypoint print]; } return 0; }
// // Mypoint.h // mylearn // #ifndef mylearn_Mypoint_h #define mylearn_Mypoint_h @interface Mypoint:NSObject { int myx; int myy; } @property int z; -(void) print; -(void) setx:(int)x; -(void) sety:(int)y; -(int) myx; -(int) myy; -(void) sayz; +(void)sayhello; -(int)distx1:(int)x1 distx2:(int)x2 disty1:(int)y1 disty2:(int)y2; @end #endif
2016-09-07 21:39:21.980 mylearn[621:52408] hello
2016-09-07 21:39:21.981 mylearn[621:52408] 10,20,16
2016-09-07 21:39:21.982 mylearn[621:52408] dist:19
2016-09-07 21:39:21.982 mylearn[621:52408] point:
2016-09-07 21:39:21.982 mylearn[621:52408] 10
2016-09-07 21:39:21.982 mylearn[621:52408] (10,20)