【问题标题】:What are the default options for a @property declaration in ARC?ARC 中 @property 声明的默认选项是什么?
【发布时间】:2026-02-17 15:10:01
【问题描述】:

如果我的 .h 文件中有以下内容:

@property UIButton *connect;

这是否与:

@property(atomic, strong) UIButton *connect;

例如,@property 声明中的默认“参数”是什么?

【问题讨论】:

标签: iphone objective-c properties automatic-ref-counting


【解决方案1】:

根据文档,属性默认为 atomicstrong

Properties are Atomic by Default

Use Strong and Weak Declarations to Manage Ownership - 看下一句。

【讨论】:

  • 非常感谢。我目前正在教 iOS 开发,并认为在没有“参数”的情况下只教 @property 方法会更容易——只是想确保它们是合理的默认值。
  • @Downvoter - 为什么投反对票?该问题已通过文档链接得到正确回答。
  • 是的,至少在投反对票之前留下一些评论。否则就是消极心态。
  • @rmaddy:我不赞成。但我仍然很困惑...*.com/questions/15362157/…
  • @AnoopVaidya 文档声明属性默认是原子的。有什么困惑?
【解决方案2】:

strongatomic 是属性声明中的默认选项,请参阅此链接:link

【讨论】:

    【解决方案3】:

    是的。 atomicstrong 是默认属性。尽管花费的时间比我想象的要长,但它似乎在文档中散布开来:

    http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html

    【讨论】:

      【解决方案4】:

      默认情况下,属性是原子的,如 here 所记录的那样,并且如 here 所提到的那样强大(参见上面的“避免强引用循环”)

      【讨论】: