gpt4 book ai didi

objective-c - Objective-C 属性的默认属性是什么?

转载 作者:IT老高 更新时间:2023-10-28 11:42:56 25 4
gpt4 key购买 nike

当您没有在 Objective-C 中列出任何属性时,属性的默认属性是什么?

例如,如果我这样写:

@property float value;

默认值是什么,比如它是只读的,它是否保留......等等?

最佳答案

默认/隐式值为 atomicreadwriteassign

原子

这意味着该值是原子读/写的。与有些流行的误解相反,原子性等同于线程安全。简单来说,它保证您读取或写入的值将被整体读取或写入(当使用访问器时)。即使你一直使用访问器,它也不是严格线程安全的。

读写

该属性有一个 setter 和一个 getter。

分配

此默认值通常用于 POD(Plain-Old-Data)和内置类型(例如 int)。

对于 NSObject 类型,您会倾向于持有强引用。在大多数情况下,您将声明属性 copystrongretainassign 不执行引用计数操作。另见:http://clang.llvm.org/docs/AutomaticReferenceCounting.html#property-declarations

在某些情况下,该属性在 ARC 下可能是隐式 strong:

A property of retainable object pointer type which is synthesized without a source of ownership has the ownership of its associated instance variable, if it already exists; otherwise, [beginning Apple 3.1, LLVM 3.1] its ownership is implicitly strong. Prior to this revision, it was ill-formed to synthesize such a property.

关于objective-c - Objective-C 属性的默认属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com