Objective-C:"@ synthesize fooBar;"与"@synthesize fooBar = _fooBar;" [英] Objective-C: `@synthesize fooBar;` vs. `@synthesize fooBar=_fooBar;`

查看:73
本文介绍了Objective-C:"@ synthesize fooBar;"与"@synthesize fooBar = _fooBar;"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
合成属性和带下划线前缀的变量:是什么这是什么意思?

Possible Duplicate:
Synthesized property and variable with underscore prefix: what does this mean?

我已经在代码中看到了这两个;有什么区别?

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;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆