gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:33:25 25 4
gpt4 key购买 nike

我们知道,在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/

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