财产申报帮助 [英] Property declaration help

查看:311
本文介绍了财产申报帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
可可Objective-C类中变量前面的下划线如何工作?

Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?

我已经看到许多在线示例,其中它们使用以下编码风格进行属性声明:

I have seen many online examples where they use the following coding style for property declaration:

@interface Book : NSObject 
{
  NSString *_title;
}

@property (nonatomic, retain) NSString *title;
@end

在实施中:

@implementation Book
@synthesize title = _title;
@end

问题是为什么我们要使用下划线?

Question is why we are using underscore?

推荐答案

如果使用下划线约定,您可以一眼就知道代码是在类方法中使用属性还是类成员变量.没有任何技术原因,这是个人喜好.根据您的操作,它可能会有所帮助.如果您选择不这样做,那肯定没有必要.

If you use an underscore convention you can know at a glance if code is using a property or a class member variable within class methods. There's no technical reason for this, it's personal preference. Depending on what you are doing it can be helpful. It's certainly not necessary if you choose not to do it.

这篇关于财产申报帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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