• 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

  • 相关阅读:
    BUAA OO Unit1 表达式求导
    中介者模式
    命令模式
    观察者模式
    解释器模式
    策略模式
    迭代器模式
    模板方法模式
    代理模式
    桥接模式
  • 原文地址:https://www.cnblogs.com/hyuganatsu/p/property-point.html
Copyright © 2020-2023  润新知