@property 与 ARC 的定义:强还是保留?
使用 Xcode 4.2 和 ARC,我注意到 NSManagedObject
自动生成的代码对于属性来说仍然是这样的:
@property (nonatomic, retain) NSString * someString;
1) Shouldn't retain
now be Replaced with 强
还是弱
?
2) 为什么自动生成的代码仍然使用 retain
3) 此属性语句中 retain
的正确替换是什么?
我目前正在使用 NSFetchRequest
调试问题,我认为这可能是问题的根源。想法?
Using Xcode 4.2 and ARC, I notice that the auto-generated code for an NSManagedObject
still reads like this for properties:
@property (nonatomic, retain) NSString * someString;
1) Shouldn't retain
now be replace with strong
or weak
?
2) Why does the auto-generated code still use retain
3) What is the correct replacement for retain
in this property statement?
I'm currently debugging a problem using NSFetchRequest
, and I thought this might be the source of the problem. Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不可以。你不能用weak代替retain;他们是不同的。强是 100% 保留的同义词;它们是相同的。您可以使用其中任何一个,因此这里没有“应该”。如果您愿意,可以将保留替换为强,但不是必须这样做。
为什么不呢?参见(1)。保留是正确的,所以没有问题。
无需更换retain。
事实并非如此。
No. You cannot replace retain with weak; they are different. And strong is a 100% synonym for retain; they are identical. You can use either, so there is no "should" here. You can replace retain with strong if you like, but you don't have to.
Why not? See (1). retain is correct so there is no problem.
There is no need to replace retain.
It isn't.
一并回答所有三个问题:
retain
和strong
是同义词,因此两者都是正确的。 文档指出To answer all three questions in one:
retain
andstrong
are synonymous with each other, so both are correct. The documentation states在 ARC 之前,您必须“释放”保留的对象。这意味着保留有对应的部分。 ARC之后你不需要释放。所以用强。这是一个视觉线索,表明您不需要调用发布。
Before ARC, you have to 'release' an object which is retained. That mean retain has counter part. After ARC you don't need to release. So use strong. Its a visual clue that you don't need to call release.
“留”等于“强”。
例如使用“strong”:
并且例如使用“__strong”:
在 Apple Docs 上。说:
属性属性
引入关键字weak和strong作为新声明的属性属性,如以下示例所示。
苹果文档。 http://developer.apple.com/库/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
"retain" is equals to "strong".
"strong" is used for example:
And "__strong" is used for example:
On Apple Docs. says:
Property Attributes
The keywords weak and strong are introduced as new declared property attributes, as shown in the following examples.
Apple doc. http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html