IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]OC-6

    u010255642发表于 2016-09-13 13:42:06
    love 0
    //
    //  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)getdist:(int)xx1 :(int)xx2 :(int)yy1 :(int)yy2{
        return (int)sqrt((xx1-xx2)*(xx1-xx2)+(yy1-yy2)*(yy1-yy2));
    }
    
    -(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(@"getdist:%i",[mypoint getdist:10 :6 :9 :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;
    //不带参数名的多参数方法
    -(int)getdist:(int)xx1 :(int)xx2 :(int)xx3 :(int)xx4;
    @end
    
    #endif
    




沪ICP备19023445号-2号
友情链接