設計一部iphone手機用物件導向的方法

來源:互聯網
上載者:User

標籤:快速鍵   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手機用物件導向的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.