扩展

@interface CPoint : NSObject
@property double x,y;
-(id)initWithX: (double) x Y: (double) y;
@end

@implementation CPoint
-(id)initWithX: (double) x Y: (double) y {
    self = [super init];
    if (self) {
        self.x = x;
        self.y = y;
    }
    return self;
}
@end

@interface CPoint (CPointTypeExtension)
+(double)getDistanceFromPoint: (CPoint *) p1 toPoint: (CPoint *) p2;
@end

@implementation CPoint (CPointTypeExtension)
+(double)getDistanceFromPoint: (CPoint *) p1 toPoint: (CPoint *) p2 {
    double d1 = pow(p1.x - p2.x2);
    double d2 = pow(p1.y - p2.y2);
    return sqrt(d1 + d2);
}
@end

CPoint * p1 = [[CPoint alloc] initWithX:1 Y:2];
CPoint * p2 = [[CPoint alloc] initWithX:2 Y:3];
double distance = [CPoint getDistanceFromPoint:p1 toPoint:p2];
//distance is 1.4142