为MYPoint类写一个分类

原文链接:http://www.cnblogs.com/wsq724439564/p/3272967.html
 1 #import <Foundation/Foundation.h>
 2 //xieyi
 3 @protocol showOn
 4 @required 
 5 -(void)printOn;
 6 @end
 7 // lei
 8 @interface MyPoint : NSObject<showOn,NSCopying>{
 9     int x;
10     int y;
11 }
12 @property (nonatomic,assign)int x,y;
13 -(id)initWithX:(int)_x andY:(int)_y;
14 @end
15 // leibie fenlei
16 @interface MyPoint(MoveSet)
17 
18 -(void)moveToX:(int)_x andY:(int)_y;
19 
20 @end
21 
22 
23 #import "MyPoint.h"
24 
25 @implementation MyPoint
26 @synthesize x,y;
27 
28 -(id)initWithX:(int)_x andY:(int)_y{
29     if(_x==0)
30         x=1;
31     if(_y==0)
32         y=1;
33     x=_x;
34     y=_y;
35     return self;
36 }
37 
38 -(id)copyWithZone:(NSZone *)zone{
39     MyPoint* newPoint=[[MyPoint allocWithZone:zone] initWithX:x andY:y];
40     return newPoint;
41 }
42 
43 -(void)printOn{
44     NSLog(@" x = %d , y = %d ",x,y);
45 }
46 
47 @end
48 
49 @implementation MyPoint(MoveSet)
50 
51 -(void)moveToX:(int)_x andY:(int)_y{
52     x=_x;
53     y=_y;
54 }
55 
56 @end

 

转载于:https://www.cnblogs.com/wsq724439564/p/3272967.html

上一篇:python编程---Linux python基本使用方法


下一篇:贝索斯宣布“退位”