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