52,对象方法

#import


@interface Iphone : NSObject

{

    @public

    char *name;

    int size;

}


//1,没有返回值没有参数,对象函数调用属性

-(void)getIphoneInfo;

//2,没有返回值有参数

-(void)sendMessage:(char *)message;

//3,有返回值没有参数

-(int)getNum;

//4,有返回值有参数

-(NSString *)sendIphoneMessage:(int)number :(char *)message;

//5,带标记的方法

-(int)sumWithNum1:(int)num1 andNum2:(int)num2;



@end


@implementation Iphone


-(void)getIphoneInfo{

NSLog(@"Iphone Info:name = %s,size = %i",name,size);

}


-(void)sendMessage:(char *)content{

    NSLog(@"message = %s",content);

}


-(int)getNum{

    return 1;

}


-(NSString *)sendIphoneMessage:(int)number :(char *)content{

    NSString *message = [[NSString alloc] initWithString:[NSString stringWithFormat:@"number = %i,content = %s",number,content]];

    return message;

}


-(int)sumWithNum1:(int)num1 andNum2:(int)num2{

    return num1 + num2;

}


@end


int main(int argc, const char * argv[]) {

    @autoreleasepool {

        Iphone *iphone = [Iphone new];

        iphone->name = "ljs";

        iphone->size = 12;

        [iphone getIphoneInfo];

        [iphone sendMessage:"This is as message!"];

        NSLog(@"Num = %i",[iphone getNum]);

        NSLog(@"Message = %@",[iphone sendIphoneMessage:221 :"hi"]);

        NSLog(@"result = %i",[iphone sumWithNum1:10 andNum2:20]);

    }

    return 0;

}


你可能感兴趣的:(OC)