Employee.h

@interface Employee:NSObject

{

  int _employeeNumber;

  NSString *_name;

  Employee*_supervisitor;

  int _salary;

}

@property int employeeNumber;

@property(nonatomic,retain) NSString * name;

@property(nonatomic,retain)Employee *supervisitor;

@property int salary;

......

@end

Employee.m

@implementation Employee

@synthesize employeeNumber;

@synthesize name;

//@synthesize supervistor;//在这不要实现setter和getter下面手动实现

@synthesize salary;

-(void)setSupervistor:(Employee *)newSupervisitor

{

  [newSupervistor retain];

  [_supervistor release];

  _supervistor=newSupervisitor;

}

-(Employee*)supervisitor

{

  return _supervisitor;

}

//上面代码解释:上面代码的顺序很重要。向存储在supervisitor中的当前对象发送一条release消息,会对应当存储它的时候所接受的一条retain消息

 

 

 

 

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-05-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案