zoukankan      html  css  js  c++  java
  • Programming with Objective-C -- 属性的缺省实现

    Programming with Objective-C  -- 属性的缺省实现

    https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithObjects/WorkingwithObjects.html#//apple_ref/doc/uid/TP40011210-CH4-SW6

    Properties Are Atomic by Default

    By default, an Objective-C property is atomic:

    Note: The opposite of readonly is readwrite. There’s no need to specify the readwrite attribute explicitly, because it is the default.

    Most Properties Are Backed by Instance Variables

    By default, a readwrite property will be backed by an instance variable, which will again be synthesized automatically by the compiler.

    You Can Customize Synthesized Instance Variable Names

    As mentioned earlier, the default behavior for a writeable property is to use an instance variable called _propertyName.

    By default, both Objective-C properties and variables maintain strong references to their objects. This is fine for many situations, but it does cause a potential problem with strong reference cycles.

    Use Strong and Weak Declarations to Manage Ownership

    By default, object properties declared like this:

    @property id delegate;

    use strong references for their synthesized instance variables. To declare a weak reference, add an attribute to the property, like this:

    @property (weak) id delegate;

    Note: The opposite to weak is strong. There’s no need to specify the strong attribute explicitly, because it is the default.

    Note: The opposite to __weak is __strong. Again, you don’t need to specify __strong explicitly, because it is the default.

  • 相关阅读:
    [笔记] Delphi 10.2.1 Tokyo 安装使用笔记
    [控件] Firemonkey 跨平台 Toast
    [iOS] Edit / Memo 原生控件才提供拼字检查
    [外观] Firemonkey Windows Hint 气球样式
    SQL实现value为1,2,3转换为值
    关于python的一些坑
    Python JSON
    python 字典拷贝
    python 日期、时间、字符串相互转换
    python获取cookie的方法
  • 原文地址:https://www.cnblogs.com/feng9exe/p/12628126.html
Copyright © 2011-2022 走看看