@fiy-fish
2015-07-18T21:21:33.000000Z
字数 1025
阅读 1513
Objective-c
// main.m
// 指定对象使用属性
//
// Created by Aaron on 15/7/9.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Person.h"
#import "Animal.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *p = [[Person alloc] init];
Tool *t = [[Tool alloc] init];
p.tool = t;
p.tool.knif = @"小李飞刀";
NSLog(@"p.tool.knif--->%@",p.tool.knif);
Animal *aniaml = [[Animal alloc] init];
aniaml.tool = t;
aniaml.tool.knif = @"....";
NSLog(@"aniaml.tool.knif--->%@",aniaml.tool.knif);
}
return 0;
}
#import <Foundation/Foundation.h>
#import "Tool.h"
@interface Animal : NSObject
@property (nonatomic,retain) Tool *tool;
@end
#import "Animal.h"
@implementation Animal
@end
#import <Foundation/Foundation.h>
@interface Tool : NSObject
@end
#import "Tool.h"
@interface Tool ()
@property (nonatomic,copy) NSString *knif;
@end
@implementation Tool
@end
#import <Foundation/Foundation.h>
#import "Tool.h"
@interface Person : NSObject
@property (nonatomic,retain) Tool *tool;
@end
@interface Tool (PersonUse)
@property (nonatomic,copy) NSString *knif;
@end
#import "Person.h"
@implementation Person
@end