The construction method, the Int method, does not accept any arguments, and in the actual development process, the construction method is often customized for convenience. Therefore, the following is a description of the implementation of the construction method and the custom construction method.
#import <Foundation/Foundation.h>
#import "Iphone.h"
int main (int argc, const CHARCHAR * argv[])
{
/*
iphone * phone1 = [iphone new];
PHONE1->_CPU = 1.5;
Phone1->_ram = A;
* */*iphone * phone = [Iphone alloc];//offcc
phone = [phone INIT];//[0FFCC init];
*//Open up memory space, and initialize member variable merge to call
iphone * phone = [[iphone ALLOC]INIT];//[0FFCC init];
Phone->_ram = A;
NSLog (@ "%@", phone);
iphone * phone2 = [[iphone alloc] initwithiphonesize:iphonesize4point0];
NSLog (@ "%@", phone2);
iphone * phone3 = [[iphone alloc] initwithiphonesize:iphonesize4point0 Andphonecolor:iphonecolorblack];
return 0;
}
#import <Foundation/Foundation.h> enum Iphonesize {iphonesize3point5,//3.5 inch screen iphonesize4point0,//4.0 inch screens
iphonesize4point7,//4.7 inch screen iphonesize5point5//5.5 inch screen};
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/** is used to store the Iphone screen size * *//enum iphonesize and iphonesize equivalent iphonesize _size;//
Used to store the iphone screen size/** is used to store the iphone color/iphonecolor _color;//used to store the iphone color/** used to store the CPU size * * float _cpu;
/** is used to store internal capacity/float _ram;
/** Open Flash/-(void) openflashlight;
/** Turn off flash/-(void) closeflashlight;
/** automatic */(void) Flaselightauto;
/** Photo/-(void) Camerawithflashlightstatus: (iphoneflashlightstatus) Flaselightstatus; /** returns based on incoming parametersBack to the corresponding color * *-(NSString *) Getcolorwithiphonecolor: (Iphonecolor) Iphonecolor;
+ (NSString *) Getcolorwithiphonecolor: (Iphonecolor) Iphonecolor;
Custom constructor method//1. Must be an object method//2. The construction method must be the init start-(Iphone *) Initwithiphonesize: (iphonesize) iphonesize;
-(Iphone *) Initwithiphonesize: (iphonesize) iphonesize Andphonecolor: (iphonecolor) Iphonecolor;
@end
Through the above introduction, I hope that we have the construction method and the custom construction method has the understanding and the difference, hoped that has the help to everybody.