本文介绍了Objective-C:"@ synthesize fooBar;"与"@synthesize fooBar = _fooBar;"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在代码中看到了这两个;有什么区别?
I've seen both of these in code; what's the difference?
@synthesize fooBar;
@synthesize fooBar=_fooBar;
推荐答案
@synthesize fooBar;
使用具有相同名称的实例变量为存储fooBar
创建访问器,而=_fooBar
告诉编译器使用实例变量名为_fooBar
作为存储.如果实例变量和属性的名称相同,则无需使用=...
.否则,请使用
@synthesize fooBar;
creates accessors for the property fooBar
using an instance variable with the same name for storage, while the =_fooBar
tells the compiler to use the instance variable named _fooBar
as storage instead. You don't need to use the =...
if you have your instance variables and properties identically named, and you do otherwise.
这篇关于Objective-C:"@ synthesize fooBar;"与"@synthesize fooBar = _fooBar;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!