标签:ios开发 objective-c mac 构造方法 枚举
// // 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];//[0ffcc init]; */ //开辟内存空间,以及初始化成员变量合并一起调用 Iphone * phone = [[Iphone alloc]init];//[0ffcc 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寸屏幕 IphoneSize4point0,//4.0寸屏幕 IphoneSize4point7,//4.7寸屏幕 IphoneSize5point5 //5.5寸屏幕 }; 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 /** 用来存储iPhone屏幕尺寸 */ //enum IphoneSize 与IphoneSize 等价 IphoneSize _size;//用来存储iPhone屏幕尺寸 /** 用来存储iPhone颜色 */ IphoneColor _color;//用来存储iPhone颜色 /** 用来存储cpu大小 */ float _cpu; /** 用来存储内部容量大小 */ float _ram; } /**打开闪光灯*/ -(void)openFlashLight; /**关闭闪光灯*/ -(void)closeFlashLight; /**自动*/ -(void)flaseLightAuto; /**拍照*/ -(void) cameraWithFlashLightStatus:(IphoneFlashLightStatus)flaseLightStatus; /**根据传入参数返回相应颜色*/ -(NSString * )getColorWithIphoneColor:(IphoneColor)iphoneColor; +(NSString *)getColorWithIphoneColor:(IphoneColor)iphoneColor; //自定义构造方法 //1.一定是对象方法 //2.构造方法一定是init开头 -(Iphone *)initWithIphoneSize:(IphoneSize)iphoneSize; -(Iphone *)initWithIphoneSize:(IphoneSize)iphoneSize andPhoneColor:(IphoneColor)iphoneColor; @end
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:ios开发 objective-c mac 构造方法 枚举
原文地址:http://blog.csdn.net/u012701023/article/details/46980413