Xcode4 模板现在在 iVars 上使用下划线?
我注意到,在 Xcode4 中,Apple 更新了应用程序模板,在实例变量之前包含下划线。
// Xcode4
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window = _window;
。
// Xcode3
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window;
我知道对于有用性存在不同意见但我只是好奇更新后的模板是否:
- (1) 突出显示新的最佳实践。
- (2) 展示苹果是如何做事的,但意思是让你用老方法做事。
- (3)这只是个人口味,无所谓。
I have noticed that with Xcode4 Apple has updated the application templates to include underscores before instance variables.
// Xcode4
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window = _window;
.
// Xcode3
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window;
I know there are differing opinions on the usefulness of this but I was just curious if the updated templates where:
- (1) Highlighting a new best practice.
- (2) Showing how Apple does things but meaning for you to do it the old way.
- (3) Its just personal taste, it does not matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很有趣,因为在过去(iOS 之前),Apple 曾经 不鼓励对 ivars 使用下划线前缀:
但在现代 Objective-C 运行时中,我相信子类中的 ivar 命名冲突已经消除,所以这不再是问题。所以我认为这就是为什么他们让模板默认使用下划线前缀,以匹配苹果的内部代码。
It's interesting because in the past (pre-iOS), Apple used to discourage the use of underscore prefixes for ivars:
But with a modern Objective-C runtime, I believe ivar naming conflicts in subclasses has been eliminated, so this is not a problem anymore. So I think that's why they're making the templates use an underscore prefix by default, to match what Apple's internal code looks like.