作者:LAMP小白 点击:2442 发布日期:2014-04-17 01:09:27 返回列表
这是一种PHP没有的结构,类似于数组
// // main.m // say_hellow // // Created by 刘立博 on 14-4-15. // Copyright (c) 2014年 刘立博. All rights reserved. // #import <Foundation/Foundation.h> typedef enum{ kCircle, kRectangle, kEgg } ShapeType; typedef enum{ kRedColor, kGreenColor, kBlueColor } ShapeColor; typedef struct{ int x,y,width,height; } ShapeRect; typedef struct{ ShapeType type; ShapeColor fill_color; ShapeRect bounds; } Shape; void drawkCircle(ShapeRect bounds,ShapeColor fill_color) { NSLog(@"draw circle"); } void drawkRectangle(ShapeRect bounds,ShapeColor fill_color) { NSLog(@"draw Rectangle"); } void drawkEgg(ShapeRect bounds,ShapeColor fill_color) { NSLog(@"draw Egg"); } void drawShapes(Shape shapes[], int count) { for (int i = 0; i<count; i++) { switch (shapes[i].type) { case kCircle: drawkCircle(shapes[i].bounds,shapes[i].fill_color); break; case kRectangle: drawkRectangle(shapes[i].bounds,shapes[i].fill_color); break; case kEgg: drawkEgg(shapes[i].bounds,shapes[i].fill_color); break; default: break; } } } int main(int argc, const char * argv[]) { Shape shapes[3]; ShapeRect rect0 = {0,0,10,30}; shapes[0].type = kCircle; shapes[0].fill_color = kRedColor; shapes[0].bounds = rect0; ShapeRect rect1 = {0,0,10,30}; shapes[1].type = kRectangle; shapes[1].fill_color = kGreenColor; shapes[1].bounds = rect1; ShapeRect rect2 = {0,0,10,30}; shapes[2].type = kEgg; shapes[2].fill_color = kBlueColor; shapes[2].bounds = rect2; drawShapes(shapes,3); return 0; }
上一篇:xcode加入启动参数 下一篇:快递查询API