码迷,mamicode.com
首页 > 其他好文 > 详细

oc-15-枚举结构体

时间:2016-03-23 00:38:41      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

Cat.h

#import <Foundation/Foundation.h>
// 颜色的枚举

typedef enum{
    
  ColorBlack,
  ColorYeallow
    
} Color;
@interface Cat : NSObject
{
    @public
    float _weight;   // 体重
    Color hairColor; // 毛色
}

//
- (void)jump;

//
- (void)eat;
@end

Girl.h

#import <Foundation/Foundation.h>
#import "Cat.h"

// 生日
typedef struct
{
    int year;
    int month;
    int day;

}Birthday;

@interface Girl : NSObject
{
    @public
    NSString *_name;  // 名字
    Birthday _birth; // 生日
    BOOL _gender;     // 性别  1是男 0是女
    Cat *_cat;        //
}

// 喂猫
- (void)feedWithCat:(Cat *)cat;

// 玩猫
- (void)playWithCat:(Cat *)cat;


// 展示女孩信息
- (void)show;
@end

Girl.m

#import "Girl.h"

@implementation Girl

// 喂猫
- (void)feedWithCat:(Cat *)cat
{
    NSLog(@"喂猫啦!!!!");
    [cat eat];
}

// 玩猫
- (void)playWithCat:(Cat *)cat
{
    NSLog(@"玩猫啦////");
    [cat jump];
}
// 展示女孩信息
- (void)show
{
    //访问结构体变量用->
    NSLog(@"女孩的名字:%@,生日:%d-%d-%d,性别:%d",_name,_birth->year,_birth->month,_birth->day,_gender);
}
@end

 

oc-15-枚举结构体

标签:

原文地址:http://www.cnblogs.com/yaowen/p/5309050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!