我读了很多关于这个主题的帖子,但我无法完全理解一切.好的,很清楚
self.text = @"MyText" will call the accessory method setText (autogenerated)
_text = @"MyText" will still assign the value but will not call the setText
Run Code Online (Sandbox Code Playgroud)
这很清楚.
但是当我们不使用ARC时,这可能很有用,因为setText将负责内存管理.但是当我们使用ARC时会发生什么?有时如果我使用_text一切正常,有时候如果我不使用"self.text"我的应用程序将无法工作.
那么真正的区别是什么?必须有的不仅仅是内存管理.
让我说我有这个
@interface MyClass:NSObject {
NSMutableString *text;
}
@property (nonatomic ) NSMutableString *text;
Run Code Online (Sandbox Code Playgroud)
在这种情况下是不是相同的呼吁
self.text = @"ok"
Run Code Online (Sandbox Code Playgroud)
要么
text = @"ok" ?
Run Code Online (Sandbox Code Playgroud)
有什么不同?