[关闭]
@fiy-fish 2015-07-18T21:21:33.000000Z 字数 1025 阅读 1534

day07-03-指定对象使用属性

Objective-c


  1. // main.m
  2. // 指定对象使用属性
  3. //
  4. // Created by Aaron on 15/7/9.
  5. // Copyright (c) 2015年 Aaron. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "Person.h"
  9. #import "Animal.h"
  10. int main(int argc, const char * argv[]) {
  11. @autoreleasepool {
  12. Person *p = [[Person alloc] init];
  13. Tool *t = [[Tool alloc] init];
  14. p.tool = t;
  15. p.tool.knif = @"小李飞刀";
  16. NSLog(@"p.tool.knif--->%@",p.tool.knif);
  17. Animal *aniaml = [[Animal alloc] init];
  18. aniaml.tool = t;
  19. aniaml.tool.knif = @"....";
  20. NSLog(@"aniaml.tool.knif--->%@",aniaml.tool.knif);
  21. }
  22. return 0;
  23. }

  1. #import <Foundation/Foundation.h>
  2. #import "Tool.h"
  3. @interface Animal : NSObject
  4. @property (nonatomic,retain) Tool *tool;
  5. @end

  1. #import "Animal.h"
  2. @implementation Animal
  3. @end

  1. #import <Foundation/Foundation.h>
  2. @interface Tool : NSObject
  3. @end

  1. #import "Tool.h"
  2. @interface Tool ()
  3. @property (nonatomic,copy) NSString *knif;
  4. @end
  5. @implementation Tool
  6. @end

  1. #import <Foundation/Foundation.h>
  2. #import "Tool.h"
  3. @interface Person : NSObject
  4. @property (nonatomic,retain) Tool *tool;
  5. @end
  6. @interface Tool (PersonUse)
  7. @property (nonatomic,copy) NSString *knif;
  8. @end

  1. #import "Person.h"
  2. @implementation Person
  3. @end
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注