码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-06-04 13:51:34      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:快捷键   com   main   phone   log   存储   turn   优化   pre   

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手机用面向对象的方法

标签:快捷键   com   main   phone   log   存储   turn   优化   pre   

原文地址:http://www.cnblogs.com/wzjhoutai/p/6940164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!