Construction method, Custom construction method

Source: Internet
Author: 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 = +;    */      /*iphone * phone = [Iphone alloc];//offcc        phone = [phone INIT];//[0FFCC init];    *    ///Open up memory space, and initialize member variable merge call    iphone * phone = [[iphone ALLOC]INIT];//[0FFCC init];    Phone->_ram = +;        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 inch screen IphoneSize4point0,/    /4.0 inch screen iphonesize4point7,//4.7 inch screen iphonesize5point5//5.5 inch screen};typedef enum iphonesize iphonesize;enum IphoneColor{ Iphonecolorwhite, iphonecolorblack};typedef enum Iphonecolor iphonecolor;enum iphoneflashlightstatus{IphoneFlash Lightstatusopen, Iphoneflashlightstatusclose, iphoneflashlightstatusauto};typedef enum IphoneFlashLightStatus Iphon    eflashlightstatus; @interface iphone:nsobject{@public/** to store Iphone screen size *///enum iphonesize and iphonesize equivalent    Iphonesize _size;//used to store iphone screen size/** used to store iphone color */Iphonecolor _color;//used to store iphone color/** used to store CPU size */    float _cpu; /** used to store internal capacity */float _ram;} /** Open Flash */-(void) openflashlight;/** off flash */-(void) closeflashlight;/** auto */-(void) flaselightauto;/** photo */-(void) Camerawithflashlightstatus: (iphoneflashlightstatus) flaselightstatus;/** returns the corresponding color */-(NSString *) According to the incoming parameters GetColorWithIPhonecolor: (Iphonecolor) iphonecolor;+ (NSString *) Getcolorwithiphonecolor: (iphonecolor) iphonecolor;//Custom construction method//1. Must be the object method//2. Construction method must be init-(iphone *) Initwithiphonesize: (iphonesize) iphonesize;-(iphone *) Initwithiphonesize: ( iphonesize) iphonesize Andphonecolor: (iphonecolor) Iphonecolor; @end


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Construction method, Custom construction method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.