[关闭]
@fiy-fish 2015-07-18T19:50:49.000000Z 字数 926 阅读 1245

day06-05-类簇

Objective-c


  1. // main.m
  2. // 类簇
  3. //
  4. // Created by Aaron on 15/7/8.
  5. // Copyright (c) 2015年 Aaron. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "Shape.h"
  9. int main(int argc, const char * argv[]) {
  10. @autoreleasepool {
  11. Shape *shape = [Shape createShapeWithType:kShapeYX];
  12. NSLog(@"%@",shape);
  13. [shape draw];
  14. NSString *str = [NSString stringWithContentsOfFile:@"/users/qianfeng/desktop/file1.txt" encoding:NSUTF8StringEncoding error:nil];
  15. }
  16. return 0;
  17. }

  1. #import <Foundation/Foundation.h>
  2. typedef enum
  3. {
  4. kShapeSJX,
  5. kShapeZFX,
  6. kShapeYX
  7. }ShapeType;
  8. @interface Shape : NSObject
  9. {
  10. NSString *_name;
  11. }
  12. +(instancetype)createShapeWithType:(ShapeType)type;
  13. -(void)draw;
  14. @end

  1. #import "Shape.h"
  2. #import "ShapeSJX.h"
  3. #import "ShapeYX.h"
  4. #import "ShapeZFX.h"
  5. @implementation Shape
  6. +(instancetype)createShapeWithType:(ShapeType)type
  7. {
  8. NSArray *array = @[[ShapeSJX class],[ShapeZFX class],[ShapeYX class]];
  9. Shape *s = [[array[type] alloc] init];
  10. return s;
  11. }
  12. -(NSString *)description
  13. {
  14. return _name;
  15. }
  16. -(void)draw
  17. {
  18. NSLog(@"....");
  19. }
  20. @end

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注