I was wondering what is the correct way to write synthesised properties for primitive data types (like bool
) when ARC is enabled.
我想知道在启用ARC时,为原始数据类型(如bool)编写synthesised属性的正确方法是什么。
I used to use this before ARC:
我以前用过这个圆弧:
@property(assign) bool isOn;
But it is my understanding (maybe wrong) that you shouldn't use assign
when ARC is enabled. I tried replacing this with weak
but I get the error -
但是我的理解是(可能是错误的)您不应该在启用ARC时使用assign。我试着用弱键替换它,但我得到了错误-
Property of "weak" attribute must be of type object.
“弱”属性的属性必须是类型对象。
Should I continue to use assign
?
我应该继续使用assign吗?
3 个解决方案
#1
29
Assign
is fine. ARC stands for "Automatic Reference Counting", and primitive data types do not have reference counts.
分配好。ARC表示“自动引用计数”,原始数据类型没有引用计数。
Weak
failed because there is no object, nor any references for ARC to manage.
弱失败是因为没有对象,也没有要管理的弧的引用。
#2
4
Seems you need to read up on a certain subject here. Check: http://clang.llvm.org/docs/AutomaticReferenceCounting.html
看来你需要在这里读一下某一主题。检查:http://clang.llvm.org/docs/AutomaticReferenceCounting.html
Check chapter 4 ;) Here you will read that assign is fine with ARC.
检查;第四章)这里你会看到赋值对于ARC是没问题的。
#3
0
When ARC Enabled you can write synthesised properties for primitive data like(ex:BOOL).. @property(unsafe_unretained) bool isOn;
当启用了ARC时,您可以为原始数据(例如:BOOL)编写合成属性。@ property(unsafe_unretained)bool关;
#1
29
Assign
is fine. ARC stands for "Automatic Reference Counting", and primitive data types do not have reference counts.
分配好。ARC表示“自动引用计数”,原始数据类型没有引用计数。
Weak
failed because there is no object, nor any references for ARC to manage.
弱失败是因为没有对象,也没有要管理的弧的引用。
#2
4
Seems you need to read up on a certain subject here. Check: http://clang.llvm.org/docs/AutomaticReferenceCounting.html
看来你需要在这里读一下某一主题。检查:http://clang.llvm.org/docs/AutomaticReferenceCounting.html
Check chapter 4 ;) Here you will read that assign is fine with ARC.
检查;第四章)这里你会看到赋值对于ARC是没问题的。
#3
0
When ARC Enabled you can write synthesised properties for primitive data like(ex:BOOL).. @property(unsafe_unretained) bool isOn;
当启用了ARC时,您可以为原始数据(例如:BOOL)编写合成属性。@ property(unsafe_unretained)bool关;