main函数
#import <Foundation/Foundation.h>
#import “Milk.h”
#import “Bread.h”
#import “Person.h”
int main(int argc, const char * argv[]) {
@autoreleasepool {
Milk *mk = [Milk new];
// [mk setBrand:@“純真”];
mk.brand = @“純真”;
Bread *bd = [Bread new];
bd.brand = @"回頭客";
bd.flavor = @"橙子味";
Person *pn = [Person new];
pn.name = @"葛姍";
[pn getUP];
[pn drink:mk];
[pn eat:bd];
}
return 0;
}
#import <Foundation/Foundation.h>
#import “Milk.h”
#import “Bread.h”
NS_ASSUME_NONNULL_BEGIN
@interface Person : NSObject
@property (nonatomic,copy)NSString *name;
@property int age;
-(void)getUP;
-(void)drink:(Milk *)amilk;
-(void)eat:(Bread *)aBread;
@end
NS_ASSUME_NONNULL_END
#import “Person.h”
@implementation Person
- (void)getUP{
NSLog(@"%@ 起床了!",self.name);
}
-(void)drink:(Milk *)amilk{
NSLog(@"%@ 喝了一杯 %@ 牛奶",self.name,amilk.brand);
}
- (void)eat:(Bread *)aBread{
NSLog(@"%@ 吃了一片%@ %@面包",self.name,aBread.brand,aBread.flavor);
}
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Bread : NSObject
@property (nonatomic,copy) NSString *brand;
@property (nonatomic,copy) NSString *flavor;
@end
NS_ASSUME_NONNULL_END
#import “Bread.h”
@implementation Bread
@end
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Milk : NSObject
@property (nonatomic,copy) NSString *brand;
@end
NS_ASSUME_NONNULL_END
#import “Milk.h”
@implementation Milk
@end
注意目录