構造方法,自訂構造方法,構造方法自訂

來源:互聯網
上載者:User

構造方法,自訂構造方法,構造方法自訂

////  main.m#import <Foundation/Foundation.h>#import "Iphone.h"int main(int argc, const char * argv[]){    /*    Iphone * phone1 = [Iphone new];    phone1->_cpu = 1.5;    phone1->_ram = 512;    */      /*Iphone * phone = [Iphone alloc];//offcc        phone = [phone init];//[0ffcc init];    */    //開闢記憶體空間,以及初始化成員變數合并一起調用    Iphone * phone = [[Iphone alloc]init];//[0ffcc init];    phone->_ram = 512;        NSLog(@"%@",phone);        Iphone * phone2 = [[Iphone alloc] initWithIphoneSize:IphoneSize4point0];        NSLog(@"%@",phone2);        Iphone * phone3 = [[Iphone alloc] initWithIphoneSize:IphoneSize4point0 andPhoneColor:IphoneColorBlack];                    return 0;}
////  Iphone.h#import <Foundation/Foundation.h>enum IphoneSize{    IphoneSize3point5,//3.5寸螢幕    IphoneSize4point0,//4.0寸螢幕    IphoneSize4point7,//4.7寸螢幕    IphoneSize5point5 //5.5寸螢幕};typedef enum IphoneSize IphoneSize;enum IphoneColor{    IphoneColorWhite,    IphoneColorBlack};typedef enum IphoneColor IphoneColor;enum IphoneFlashLightStatus{    IphoneFlashLightStatusOpen,    IphoneFlashLightStatusClose,    IphoneFlashLightStatusAuto};typedef enum IphoneFlashLightStatus IphoneFlashLightStatus;@interface Iphone : NSObject{    @public    /** 用來儲存iPhone螢幕尺寸 */    //enum IphoneSize 與IphoneSize 等價    IphoneSize _size;//用來儲存iPhone螢幕尺寸    /** 用來儲存iPhone顏色 */    IphoneColor _color;//用來儲存iPhone顏色        /** 用來儲存cpu大小 */    float _cpu;    /** 用來儲存內部容量大小 */    float _ram;}/**開啟閃光燈*/-(void)openFlashLight;/**關閉閃光燈*/-(void)closeFlashLight;/**自動*/-(void)flaseLightAuto;/**拍照*/-(void) cameraWithFlashLightStatus:(IphoneFlashLightStatus)flaseLightStatus;/**根據傳入參數返回相應顏色*/-(NSString * )getColorWithIphoneColor:(IphoneColor)iphoneColor;+(NSString *)getColorWithIphoneColor:(IphoneColor)iphoneColor;//自訂構造方法//1.一定是對象方法//2.構造方法一定是init開頭-(Iphone *)initWithIphoneSize:(IphoneSize)iphoneSize;-(Iphone *)initWithIphoneSize:(IphoneSize)iphoneSize andPhoneColor:(IphoneColor)iphoneColor;@end


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.