zoukankan      html  css  js  c++  java
  • objective-c系列-@Property&点语法

    //解释 property后边的圆括号中的修饰词的含义:

    //          nonatomic  非线程安全  非原子操作  特点是: 操作变量的效率高

    //          atomic     线程安全    原子操作   特点是: 操作变量的效率低

    //

    //          retain     强引用实例变量, setter方法中会有:

    //                                  -(void)setXXX:(xxx)arg

    //                                  {

    //                                      [_属性名 release];

    //                                      _属性名 [arg retain];

    //                                  }

    //                      而且该类需要重写 dealloc方法

    //                     oc字符串的其它所有类对象都要用retain

    //

    //          copy       复制,  setter方法中会有:

    //                                  -(void)setXXX:(xxx)arg

    //                                  {

    //                                      [_属性名 release];

    //                                      _属性名 = [arg copy];

    //                                  }

    //                      而且该类需要重写 dealloc方法

    //                  copy适用的对象为: oc字符串,  block

    //

    //          assign     直接赋值,  setter方法中会有:

    //                                  -(void)setXXX:(xxx)arg

    //                                  {

    //                                      _属性名 = arg;

    //                                  }

    //                  适用于所有非对象的数据类型:int float, char, struct

    //                      union,   void *,  SEL, CLASS   BOOL 枚举

    //          readonly  不对外提供setter方法, 限定实例变量不能被外部修改

    ************************************************

    // 点语法

    @class Person;

    Person *person = [[Person alloc] init];

    person.name = @"海燕";// setter方法

    NSString *love = person.name; // getter方法

    end

  • 相关阅读:
    索引访问方法及索引优化
    AS3常用的几个顶级类
    AS3随鼠标移动的蜘蛛
    as去掉字符串中的重复字符
    AS单例模式
    移动的云朵
    (转)探索C++的秘密之详解extern "C"
    (转)YUV / RGB 格式及快速转换算法
    (转)如何解決TRDBD5M CMOS在DE2 delay的問題?
    (转)存储器类型
  • 原文地址:https://www.cnblogs.com/hyuganatsu/p/property-point.html
Copyright © 2011-2022 走看看