ios - @property definitions with ARC : strong is the default value, 但基本类型的默认值是多少?

标签 ios objective-c automatic-ref-counting

我们知道,在ARC规则下,默认值为strong,所以可以使用

@property NSString *downloadPath

但为什么是

@property (readonly) CGFloat progress
@property (readonly) BOOL isSSL 

好吗?由于它们是基本类型,因此应使用 assign。我可以这样理解ARC规则吗:

当属性为基本类型时,默认值为assign,当属性为对象类型时,默认值为strong?

最佳答案

来自clang documentation关于所有权推断:

If an object is declared with retainable object owner type, but without an explicit ownership qualifier, its type is implicitly adjusted to have __strong qualification.

原因可以在 same page 上找到。 :

Using strong by default is safe and consistent with the generic ARC rule about inferring ownership. It is, unfortunately, inconsistent with the non-ARC rule which states that such properties are implicitly assign. However, that rule is clearly untenable in ARC, since it leads to default-unsafe code.

如文档所述,默认的所有权限定符是 assign,但是对于可保留类型(又名对象),默认的限定符更改为 strong,这有助于编写安全代码的开发人员。

关于ios - @property definitions with ARC : strong is the default value, 但基本类型的默认值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34902038/

相关文章:

c# - 如何导入/包含包含对 Xamarin Studio/MonoTouch 静态内容文件的引用的文件

ios - delaySubscription 不适用于 rx_tap

ios - 如何对多个 => 约束进行优先级排序,以便它们按特定顺序生效

c++ - 使用 ARC 在 C 函数中取消引用 self,引用作为 intptr_t 传递

ios - 如何在 Swift 中清除互联网数据?

c# - 如何从web service获取流类型的数据

ios - 以编程方式激活 UISearchBar 阻止用户与其交互

objective-c - 如何管理在辅助线程中运行的 NSRunLoop 的自动释放池?

ios - NSPlaceholderString 内存泄漏与 ARC

objective-c - 将非 ARC 项目转换为 ARC