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

     

     

     

     

  • 相关阅读:
    学习Easyui
    JS链表
    Javascript数组
    布局管理器(转)
    JCombobox组合框效果实现(转)
    JComboBox
    java.lang.ClassFormatError
    JSplitPane demo
    USB OTG简单介绍
    Cookie/Session机制具体解释
  • 原文地址:https://www.cnblogs.com/zhao123/p/3189715.html
Copyright © 2011-2022 走看看