The difference and realization of the construction method and the custom construction method of IOS _ios

Source: Internet
Author: User

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.

Related Article

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.