oc-15-枚举结构体

时间:2023-03-09 16:24:48
oc-15-枚举结构体

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