Constructor, custom constructor, and custom Constructor

Source: Internet
Author: User

Constructor, custom constructor, and custom Constructor

//// 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]; // [0 ffcc init]; * // open up the memory space and combine the initialization member variables to call the Iphone * phone = [[Iphone alloc] init]; // [0 ffcc 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 inch screen IphoneSize4point0, // 4.0 inch screen IphoneSize4point7, // 4.7 inch screen IphoneSize5point5 // 5.5 inch screen}; typedef enum IphoneSize; enum IphoneColor {IphoneColorWhite, IphoneColorBlack}; typedef enum IphoneColor; enum IphoneFlashLightStatus {IphoneFlashLightStatusOpen, Shenzhen, IphoneFlashLightStatusAuto}; typedef enum IphoneFlashLightStatus; @ interface Iphone: NSObject {@ public/** is used to store the iPhone screen size * // The iPhone size and the iPhone size are equivalent to the iPhone size _ size; // used to store the iPhone screen size/** used to store the iPhone color */IphoneColor _ color; // used to store the iPhone color/** used to store the cpu size */float _ cpu; /** used to store the internal capacity */float _ ram;}/** turn on the flashlight */-(void) openFlashLight;/** turn off the flashlight */-(void) closeFlashLight;/** auto */-(void) flaseLightAuto;/** photo */-(void) cameraWithFlashLightStatus :( IphoneFlashLightStatus) flaseLightStatus; /** return the corresponding color based on input parameters */-(NSString *) getColorWithIphoneColor :( IphoneColor) iphoneColor; + (NSString *) getColorWithIphoneColor :( IphoneColor) iphoneColor; // custom constructor // 1. it must be an object method // 2. the construction method must start with init-(Iphone *) initWithIphoneSize :( IphoneSize) iphoneSize;-(Iphone *) initWithIphoneSize :( IphoneSize) iphoneSize andPhoneColor :( IphoneColor) iphoneColor; @ end


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.