每天更新的东西可能有重复的内容,当时每一部分的知识点是不同的,需要大家认真阅读
这里介绍了iOS类的合理设计,面向对象思想
main.m
#import <Foundation/Foundation.h>
#import "Iphone.h"
int main(int argc, const char * argv[])
{
Iphone * phone = [Iphone new];
phone->_color = IphoneColorWhite;
phone->_size = IphoneSize3point5;
//phone = 0ffxxx
//[0ffxxx cameraWithFlashLightStatus];
[phone cameraWithFlashLightStatus:IphoneFlashLightStatusOpen];
return 0;
}
iphone.h
@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;
@end
iphone.m
#import "Iphone.h"
@implementation Iphone
/**打开闪光灯*/
- (void)openFlashLight
{
NSLog(@"打开闪光灯");
}
/**关闭闪光灯*/
- (void)closeFlashLight
{
NSLog(@"关闭闪光灯");
}
/**自动*/
-(void)flaseLightAuto
{
NSLog(@"自动模式");
}
/**拍照*/
- (void)cameraWithFlashLightStatus:(IphoneFlashLightStatus)flaseLightStatus
{
//类的内部如何获得一个对象的地址
//self 关键字
//谁调用 self就代表谁
if(flaseLightStatus == IphoneFlashLightStatusOpen)
{
//打开闪光灯
[self openFlashLight];
}
else if(flaseLightStatus == IphoneFlashLightStatusClose)
{
[self closeFlashLight];
//关闭闪光灯
}
else
{
[self flaseLightAuto];
//自动模式
}
NSLog(@"拍照了!笑一个");
}
@end