2011-05-19 140 views
1

可能重复:
Synthesized property and variable with underscore prefix: what does this mean?目的-C:`@synthesize FOOBAR;``与FOOBAR @synthesize = _fooBar;`

我在代码看出这两种;有什么不同?

@synthesize fooBar; 

@synthesize fooBar=_fooBar; 
+3

这本身可能是一个骗局:[1](http://stackoverflow.com/questions/3521254)[3](http://stackoverflow.com/questions/822487/)[3](http:///stackoverflow.com/questions/2371489)[4](http://stackoverflow.com/questions/5582448/)[5](http://stackoverflow.com/questions/837559/)和[等等... ](http://stackoverflow.com/search?q=objc+property+underscore)请在发帖前先搜索;该系统通过在您输入您的姓名时显示指向相关问题的链接来帮助您做到这一点。 – 2011-05-19 20:12:24

回答

3

@synthesize fooBar;用于使用与存储同名的实例变量的财产fooBar创建存取,而=_fooBar告诉编译器使用名为_fooBar的存储,而不是实例变量。如果您的实例变量和属性具有相同的名称,则不需要使用=...,否则您不需要。