zoukankan      html  css  js  c++  java
  • ios特性访问器方法(setter和getter)

    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消息

     

     

     

     

  • 相关阅读:
    在线思维导图、UML
    SpringBoot定时任务
    SpringBoot邮件发送
    SpringBoot执行异步任务
    banner.txt
    SpringBoot Swagger3.0配置
    SpringBoot durid监控配置
    SpringBoot使用Shiro
    页面LOADING效果
    vue 阻止el-radio事件冒泡
  • 原文地址:https://www.cnblogs.com/zhao123/p/3189715.html
Copyright © 2011-2022 走看看