iOS:__弱vs(弱) [英] iOS: __weak vs (weak)
问题描述
这两行代码之间有区别吗?
Are there a differences between these two lines of code?
__weak IBOutlet UITextField *usernameField;
@property (weak) IBOutlet UITextField *usernameField;
如果您在.h或.m文件的接口部分中声明了这两者之一怎么办?
What if you declare either of these in interface section of the .h or the .m files?
推荐答案
是.第一个示例声明一个名为usernameField
的弱实例变量,但是第二个示例声明一个名为usernameField
的弱属性,并声明一个由属性访问的名为_usernameField
的实例变量.
Yes. The first example declares a weak instance variable called usernameField
, but the second declares a weak property called usernameField
, and an instance variable called _usernameField
that is accessed by the property.
如果在.m文件的@interface节中声明它,则只能在该.m文件中访问它(除非您与Objective-C运行时混淆).
If you declare it in an @interface section of the .m file, then it can only be accessed in that .m file (unless you mess with the Objective-C runtime).
这篇关于iOS:__弱vs(弱)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!