本帖最后由 wehuazi 于 2014-10-21 17:32 编辑
- #import <Foundation/Foundation.h>
- @interface Point2D : NSObject
- // x值的getter和setter
- @property double x;
- // y值的getter和setter
- @property double y;
- // 同时设置x和y
- - (void)setX:(double)x andY:(double)y;
- @end
- @implementation Point2D
- // 同时设置x和y
- - (void)setX:(double)x andY:(double)y
- {
- self.x = x;
- self.y = y;
- }
- @end
- int main()
- {
- Point2D *p1 = [Point2D new];
- p1.x = 15;
- p1.y = 20;
- Point2D *p2 = [Point2D new];
- // 问题代码
- p2.X:10 andY:20; // 怎么才能用点来调用对象方法呢?以实现同时设置x和y
- NSLog(@"p1=(%f,%f) and p2=(%f,%f)",p1.x,p1.y,p2.x,p2.y);
- return 0;
- }
复制代码 求大神帮忙解决!谢谢了!
|