首页 > 代码库 > 设计一部iphone手机用面向对象的方法

设计一部iphone手机用面向对象的方法

main.m


//编辑字体大小command + <
//编译执行快捷键 com + R
#import <Foundation/Foundation.h>
#import "Iphone.h"


int main(int argc, const char * argv[])
{
    Iphone * phone = [Iphone new];
    phone->_ram = 512;
    phone->_cpu = 1.5;

    int year = 2015;
    int month = 7;
    int day = 15;
    NSLog(@"Hello, World %d %d %d %@!",year,month,day,@"今天开学了");
    printf("hello world %d %d %d\n",year,month,day);
   
    
     return 0;
    
}


iphone.h

#import <Foundation/Foundation.h>

@interface Iphone : NSObject
{
    //@public 被修饰的成员变量,在类的外部能够直接訪问
    @public
    float _cpu;//用来存储CPU的大小
    float _ram;//用来存储内部容量大小
}//专门用来声明成员变量

- (void)aboutMyPhone;


-(void)sendMessag:(char *)content;

-(void)sendMessag:(char *)content andPhoneNumber:(char *)phoneNumber;

-(void)sendMessagWithMessageContent:(char *)messageContent andPhoneNumber:(char *)phoneNumber;
//2.类方法

@end


iphone.m


#import "Iphone.h"

@implementation Iphone


-(void)aboutMyPhone{

//    NSLog(@"aboutMyPhone已经实现了");
    

    NSLog(@"phone cpu %.2f,ram %.2f",_cpu,_ram);
}

-(void)sendMessag:(char *)content
{
    NSLog(@"%s",content);
}

-(void)sendMessag:(char *)content andPhoneNumber:(char *)phoneNumber
{
    NSLog(@"给%s发送消息%s",phoneNumber,content);
}
-(void)sendMessagWithMessageContent:(char *)messageContent andPhoneNumber:(char *)phoneNumber
{
    NSLog(@"给%s发送消息%s",phoneNumber,messageContent);
}


//重写description方法
-(NSString *)description
{
    //优化 return [NSString stringWithFormat:@"我的cpu=%.1f我的内部存储是=%.1fMB",_cpu,_ram];
    NSString *result = [NSString stringWithFormat:@"我的cpu=%.1f我的内部存储是=%.1fMB",_cpu,_ram];
    return result;
    return @"ffffffff";
}

@end


设计一部iphone手机用面向对象的方法